Converting fractional doy (eg. 208.572917) to a date with mm/dd/yyyy HH:MM

I have a set of data that includes doy for the year, 2013, but the doy are fractions such that July 27th at 13:45 would be represented as 208.5729167. I would like to convert this to a visual that is easier to interpret such as mm/dd/yyyy HH:MM. I've searched around and the closest function I've found converts a date to doy.
Thanks in advance

 Accepted Answer

datestr(208.5729167 + datenum('2013/01/01'),'mm/dd/yyyy HH:MM')

1 Comment

Works great, thank you! Only correction I have is that instead of 2013/01/01, 2012/12/31 should be used because this gives the accurate date since doy 208 already accounts for the 1st of the year.

Sign in to comment.

More Answers (1)

In R2014b or later, you can use datetime and duration:
>> d = datetime(2013,1,1) + days(208.5729167)
d =
28-Jul-2013 13:45:00
But bear in mind that in double precision, hours, minutes, and seconds are not exactly representable as fractions of days. Hope this helps.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!