How do you convert Month/Day to Julian Day?
11 views (last 30 days)
Show older comments
I need to convert [yyyy MMM dd (hh mm ss)] into 3-digit (decimal) julian day, but every function I try takes numbers 1-31 (for dd "day") and doesn't increment the month, so julian day output is always less than 32. I need the ability to use the "MMM" portion...
I do not have major toolboxes (i.e. one solution requires the Financial Toolbox, not viable for me)
There is a solution I have by adding monthly # of days, but I'm not sure how to account for LEAP years (when # of days in February changes).
Output should be 001-365 (with floating decimal)
0 Comments
Accepted Answer
More Answers (2)
dpb
on 29 Jul 2014
>> dn=datenum(2008,1,[1:2:400].',0,0,0); % make up some date nums
>> d=dn-dn(1); % get the day from beginning
>> [d(1:10) d(180:189)] % display some results
ans =
0 358
2 360
4 362
6 364
8 366
10 368
12 370
14 372
16 374
18 376
>>
NB: datenum handles leap years transparently--2008 was selected specifically because it was a leap year; note that day 366 did show up.
This is cumulative over years as can be observed.
A handy little utility routine is
function is=isleapyr(yr) % returns T for given year being a leapyear
is=(datenum(yr+1,1,1)-datenum(yr,1,1))==366;
Put in m-file isleapyr.m and place on matlabpath
0 Comments
Steven Lord
on 10 Nov 2016
D = datetime('today')
DOY = day(D, 'dayofyear')
Since 2016 is a leap year and today is November 10th, DOY should be (and is) 315 according to Wikipedia.
0 Comments
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!