Create month array?
20 ビュー (過去 30 日間)
古いコメントを表示
Hello,
Is it possible to create a datetime array with just entries from January to December?
I tried it like this but it did not work:
str = (1:12);
t = datetime(str(:),'InputFormat','mm');
I just want an array with 12 entries and each of them is a month with datatype "datetime"
0 件のコメント
回答 (2 件)
Stephen23
2021 年 7 月 14 日
D = datetime(2021,1,1):calmonths(1):datetime(2021,12,31)
D.Format = 'MMM'
2 件のコメント
Ali AJDER
2022 年 11 月 4 日
Hello,
Is it possible to create this datetime array independent of the year (i.e. 2021 in this example)?
Thanks.
Stephen23
2022 年 11 月 4 日
編集済み: Stephen23
2022 年 11 月 4 日
"Is it possible to create this datetime array independent of the year (i.e. 2021 in this example)?"
The DATETIME object has a YEAR property which always has some value assigned to it: if you do not assign a value to it, then the object construction will use some default value. Also due to the fact that years have different lengths (leap years, leap seconds) the exact time at the start of each month in a year can only be determined once the year has been specified. Because DATETIME objects encode exact times, the DATETIME object must specify the year.
What do you plan on doing with such an array?
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!