DateString Problem with Year

9 ビュー (過去 30 日間)
Sven
Sven 2013 年 10 月 14 日
コメント済み: Sven 2013 年 10 月 14 日
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 件のコメント
Jan
Jan 2013 年 10 月 14 日
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.

サインインしてコメントする。

採用された回答

Jan
Jan 2013 年 10 月 14 日
  1 件のコメント
Sven
Sven 2013 年 10 月 14 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by