An error with DateFormat and Date

I have no idea why the following code throws the error " MethodError: no method matching Int64(::Date). What would make the code work?

df = DateFormat("mm/dd/yyyy")
dt = Date(today(),df)
julia> Dates.format(today(), df)
"07/22/2021"
1 Like
julia> using Debugger                                                                    
                                                                                         
julia> @enter Date(today(),df)                                                           
In Date(y, m, d) at ~/julia/usr/share/julia/stdlib/v1.7/Dates/src/types.jl:411
>411  Date(y, m=1, d=1) = Date(Int64(y), Int64(m), Int64(d))                             

The default constructor for Date takes a year as its first (untyped) argument, which it then tries to convert to an Int64. If you want to format an existing date using a given DateFormat, use format as shown above by jling.

2 Likes