필터 지우기
필터 지우기

Why does datenum('n​ull','yyyy​mmdd') return an actual date?

조회 수: 5 (최근 30일)
Jean Dupin
Jean Dupin 2016년 12월 21일
답변: Jos (10584) 2016년 12월 21일
As part of date manipulation, I need to convert a whole array of string dates into numbers? This array may sometimes contain 'null' elements which I should probably take out first.
I was just curious to why
datenum('null','yyyymmdd')
returns 736330 (i.e. 01-Jan-16) and doesn't fail? For example,
datenum('null')
would return an error

채택된 답변

Jos (10584)
Jos (10584) 2016년 12월 21일
The help of DATENUM states:
Certain formats may not contain enough information to compute a date number. In those cases, hours, minutes, and seconds default to 0, days default to 1, months default to January, and years default to the current year.
Hence the value of 736330. Furthermore, if you do not specify the format identifier (the second argument), the help tells you that
If S is a string, it must be in one of the date formats 0,1,2,6,13,14,15,16,23 as defined by DATESTR.
which is definitely not the case with S being 'null'.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by