Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

How do I parse the string "29 February" into a date structure

$
0
0
using Dates
julia> format = Dates.DateFormat("d U")
dateformat"d U"

julia> parse(Date,"28 February",format) + Dates.Year(2020-1)
2020-02-28

julia> parse(Date,"29 February",format) + Dates.Year(2020-1)
ERROR: ArgumentError: Day: 29 out of range (1:28)
Stacktrace:
 [1] Date(::Int64, ::Int64, ::Int64) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/Dates/src/types.jl:223
 [2] parse(::Type{Date}, ::String, ::DateFormat{Symbol("d U"),Tuple{Dates.DatePart{'d'},Dates.Delim{Char,1},Dates.DatePart{'U'}}}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/Dates/src/parse.jl:285
 [3] top-level scope at none:0

4 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles