problem with datetime : day is wrong

year=2008
year = 2008
month=2
month = 2
day=31
day = 31
hh =[ year month day ]
hh = 1×3
2008 2 31
datetime(hh) %it's not correct ((correct day is 31 not 2)
ans = datetime
02-Mar-2008
%i try to change datetime default but the result is the same
datetime.setDefaultFormats('defaultdate','yyyy-MM-dd')
datetime(hh)
ans = datetime
2008-03-02

 採用された回答

Angelo Yeo
Angelo Yeo 2023 年 9 月 22 日

2 投票

There was no Feb 31st in 2008.

4 件のコメント

Dyuman Joshi
Dyuman Joshi 2023 年 9 月 22 日
And there is no Feb 31st in any year.
Steven Lord
Steven Lord 2023 年 9 月 22 日
If you expect that datetime should error in this scenario, there are sometimes good reasons to allow non-standard dates that represent other dates. Though a more common February non-standard date is February 30th, as stated by the largest section on that Wikipedia page.
James Tursa
James Tursa 2023 年 9 月 22 日
編集済み: James Tursa 2023 年 9 月 22 日
+1 @Steven Lord I use this feature a lot. E.g., "What date was the 200th day of the year in 1997?"
datetime(1997,1,200)
ans = datetime
19-Jul-1997
Walter Roberson
Walter Roberson 2023 年 9 月 22 日
It is a common trick to code datetime([year 1 daynumber]) instead of datetime([year 1 1])+days(daynumber-1)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTime Series Objects についてさらに検索

質問済み:

2023 年 9 月 22 日

コメント済み:

2023 年 9 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by