DateString Problem with Year

9 visualizaciones (últimos 30 días)
Sven
Sven el 14 de Oct. de 2013
Comentada: Sven el 14 de Oct. de 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 comentario
Jan
Jan el 14 de Oct. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 14 de Oct. de 2013
  1 comentario
Sven
Sven el 14 de Oct. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by