DateString Problem with Year

9 visualizzazioni (ultimi 30 giorni)
Sven
Sven il 14 Ott 2013
Commentato: Sven il 14 Ott 2013
I have a column of dates called 'Dates' in a dataset called 'Chem'. The first date is for example 4/21/11, for April 4th 2011. When I import the xlsx file to matlab this number is already converted to the datnum 39192. In matlab, I want to convert the Date column into a date string for plotting. I've tried a vast number of simple combinations including
Date=datestr(Chem.Date,'dd/mm/yyyy')
I get the year back as 04 in the first example, but the day and month are correct. This
Date=datestr(Chem.Date,'dd mm yyyy', 2000)
returns the year as 0107, even when I change the pivot year to 3000, or 1000, the year doesn't change. Adding 'local' doesn't change.Thanks.
  1 Commento
Jan
Jan il 14 Ott 2013
The question is not clear yet. What exactly is "a dataset"? Is the first date really '4/21/11' or do you get the number 39192 after importing an XLS (or XSLX or CSV?) file? It is an important difference if the date is stored as a string or as a serial date number (with Excel counting). The serial date numbers with Matlab counting differs. While I guess, that you only have to add the offset to get the Matlab serial date number, guessing is a bad idea and might be worse than not answering. So please answer my questions for clarifications first. Prefer adding new information by editing the original question, not by posting comments or pseudo-answers.

Accedi per commentare.

Risposta accettata

Jan
Jan il 14 Ott 2013
  1 Commento
Sven
Sven il 14 Ott 2013
Thanks Jan. So,the Excel serial datenumber is different from the Matlab serial date number and just needed this magical conversion factor. Thanks a million. Like you said in the above link:
%For PC: Date=Date + 693960 %For Mac: Date=Date + 695422

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by