Unable to parse julia date [duyyyy]

I am trying to read dates in the format such as “09Aug2015”. From my understanding of datetime objects the format is duyyyy. In fact when converting a date to that format it looks quite like what I want:

date_august = Dates.format(now(), DateFormat("duyyyy"))

However, when trying to read back the date I get an error:

ERROR: ArgumentError: Unable to parse date time. Expected directive DatePart(u) at char 2
 [1] macro expansion at /Applications/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/Dates/src/parse.jl:104 [inlined]
 [2] tryparsenext_core(::String, ::Int64, ::Int64, ::DateFormat{:duyyyy,Tuple{Dates.DatePart{'d'},Dates.DatePart{'u'},Dates.DatePart{'y'}}}, ::Bool) at /Applications/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/Dates/src/parse.jl:38
 [3] macro expansion at /Applications/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/Dates/src/parse.jl:150 [inlined]
 [4] tryparsenext_internal at /Applications/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/Dates/src/parse.jl:125 [inlined]
 [5] parse at /Applications/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/Dates/src/parse.jl:282 [inlined]
 [6] Date(::String, ::DateFormat{:duyyyy,Tuple{Dates.DatePart{'d'},Dates.DatePart{'u'},Dates.DatePart{'y'}}}) at /Applications/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5/Dates/src/io.jl:503
 [7] top-level scope at none:1

Any ideas on how am I to read those kinds of dates? Thks!

I don’t think anyone will be able to help really unless you turn this into a minimum working example - without knowing what date_august is it’s pretty much impossible to tell what’s going wrong.

julia> date_august = "09Aug2015"

julia> Date(date_august, dateformat"dduuuyyyy")

It is right there in the first line

So weird that to create it one needs the duyyyy format but to read it one needs uuu

You can use the same format for output too:

julia> Dates.format(now(), DateFormat("dduuuyyyy"))

The reason the duyyyy works when formatting is (I guess) since it is not ambiguous as it is when parsing.


Ah, sorry, I see what your issue is now, I somehow thought you had used a different date to read in (maybe because now() is November in my time zone :slight_smile: )