datestr producing incorrect dates

Hello everyone,
I am testing some historical data, and and the raw dates import as serialized dates. So when I convert these dates into strings in the 'yyyymmdd' format, I would expect to see the following: 39400 (serial date) converts into 20071114 (November 14, 2007). However, when I use datestr on 39400 I get 01071115. In other words, the year (2007) and the day(14th) are incorrect. Am I missing something? Thanks for reading.

답변 (2개)

per isakson
per isakson 2014년 6월 28일
편집: per isakson 2014년 6월 28일

1 개 추천

"39400" is an "Excel serial date number".
Matlab: A serial date number represents the whole and fractional number of days from a fixed, preset date (January 0, 0000).
Try
>> datenum( '20071114', 'yyyymmdd' )
ans =
733360
.
There is a function in the Financial Toolbox, x2mdate, Excel serial date number to MATLAB serial date number. See that documentation and write your own function.
Cary
Cary 2014년 6월 28일
편집: Cary 2014년 6월 28일

0 개 추천

Thank you. How can I prevent the dates from being imported as excel serial numbers (I understand I can use x2mdate if this is not possible)?

댓글 수: 1

per isakson
per isakson 2014년 6월 28일
AKAIK: One cannot prevent that and has to convert them in a second step. See my answer.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

태그

질문:

2014년 6월 28일

댓글:

2014년 6월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by