How to convert day of year (DOY) to date

Hey,
I cannot find a solution to convert DOY to date, for example

 Date("2021-146", "yyyy-ddd")

is not working.

Any ideas?
Thanks Bjoern

There isn’t currently a format character for parsing the DOY, but you can pretty easily work around this by using the builtin Date + Period math:

julia> Date("2021") + Day(146)
2021-05-27

Date("2021") will parse as 2021-01-01, then you’re adding 146 Days to that date.

4 Likes

And so if you just have to work directly from the string ds = "2021-146", you can then do:

Date(split(ds,"-")[1]) + Day(split(ds,"-")[2])
2 Likes