![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/421033/image.jpeg)
discrepancy in date conversion
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
MatLab Code N
am 20 Nov. 2020
Kommentiert: Peter Perkins
am 20 Nov. 2020
Hi,
The DT=datenum(2017,5,13,0,0,0); in matlab gives: 736828
when i convert 736828 in excel to dattime it gives 5/13/3917 12:00:00 AM.
What is the reason behind such change in the year between matlab and excel conversion?
Thanks!
0 Kommentare
Akzeptierte Antwort
Urmila
am 20 Nov. 2020
Hi,
Looks like the date format in the excel sheet is different. You can Ctrl+1 to format the cells and select the format as shown in the screenshot.
However, a better solution would be to use datetime function, DT=datetime(2017,5,13,0,0,0); This will make the variable DT to be a datetime variable and you need not have to change the format manually.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/421033/image.jpeg)
0 Kommentare
Weitere Antworten (2)
Steven Lord
am 20 Nov. 2020
See the description of the dateType input that you can pass into datetime on the documentation page for datetime, specifically the description of the 'datenum' and 'excel' values. I second Urmila's suggestion to use datetime instead of serial date numbers returned by datenum. [The documentation page for datenum makes the same recommendation.]
1 Kommentar
Peter Perkins
am 20 Nov. 2020
Yes, to add to what Steve has said:
>> datetime(736828,'ConvertFrom','datenum')
ans =
datetime
13-May-2017
>> datetime(736828,'ConvertFrom','excel')
ans =
datetime
13-May-3917
Excel uses a completely different representation that the old MATLAB datenum format. And you should stay away from using datenum at all, and use the new and better datetime instead.
Siehe auch
Kategorien
Mehr zu Calendar finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!