How to find the day number of any year from a date?
古いコメントを表示
I am very new in programming and therefore it is probably a novice's question. I have to write a script that takes a number of day(dd), month(mm) and year(yyyy)values arranged in three separate columns of a MATLAB variable and gives the day number of the year(e.g. for 03 March 2012, 31+29+3=63) as output.
採用された回答
その他の回答 (3 件)
Andrei Bobrov
2015 年 7 月 24 日
x = [2012 1 2; 2012 3 3; 2013 3 3];
d = datenum(x);
out = d - datenum(year(d),1,1) + 1;
Jos (10584)
2015 年 7 月 23 日
help datenum
and then use simple subtraction
Sergey Kostrukov
2022 年 2 月 12 日
編集済み: Sergey Kostrukov
2022 年 2 月 12 日
Fractional value of days since biginning of the year (0-364.9999):
daysFrac = days(currentTime - datetime(year(currentTime), 1, 1, TimeZone=currentTime.TimeZone))
To get the whole number starting from 1 (i.e. day index):
floor(daysFrac + 1)
カテゴリ
ヘルプ センター および File Exchange で Time Series Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!