# How to parse a string as a Date where the year is a leap one, if the year is not specified in the string?

**URL:** <https://discourse.julialang.org/t/how-to-parse-a-string-as-a-date-where-the-year-is-a-leap-one-if-the-year-is-not-specified-in-the-string/38176>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 25, 2020, 4:14am UTC](https://discourse.julialang.org/t/how-to-parse-a-string-as-a-date-where-the-year-is-a-leap-one-if-the-year-is-not-specified-in-the-string/38176 "2020-04-25T04:14:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [April 25, 2020, 4:14am UTC](https://discourse.julialang.org/t/how-to-parse-a-string-as-a-date-where-the-year-is-a-leap-one-if-the-year-is-not-specified-in-the-string/38176/1 "2020-04-25T04:14:08Z")

</div>

I have a series of date strings of the form `"01 Feb"`, `"02 Feb"`. I am trying to parse these as `Date` objects, except it fails as it doesn’t recognize that there were 29 days in Feb this year. Since the year is not specified in the date strings, is there a way to get around this?

Here is what I’m trying:

```julia
julia> Date("29 Feb",dateformat"d u")
ERROR: ArgumentError: Day: 29 out of range (1:28)
Stacktrace:
 [1] Date(::Int64, ::Int64, ::Int64) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Dates/src/types.jl:223
 [2] parse at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Dates/src/parse.jl:285 [inlined]
 [3] Date(::String, ::DateFormat{Symbol("d u"),Tuple{Dates.DatePart{'d'},Dates.Delim{Char,1},Dates.DatePart{'u'}}}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Dates/src/io.jl:503
 [4] top-level scope at REPL[16]:1

```

while this works:

```julia
julia> Date("29 Feb 2020",dateformat"d u Y")
2020-02-29

```

So one way to solve this is to append the year to the strings and then convert. I was wondering if there is a flag that I might provide to the constructor to treat the dates as a leap year without having to alter the strings?

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [April 25, 2020, 4:16am UTC](https://discourse.julialang.org/t/how-to-parse-a-string-as-a-date-where-the-year-is-a-leap-one-if-the-year-is-not-specified-in-the-string/38176/2 "2020-04-25T04:16:44Z")

</div>

I think I realize what’s going on. By default it sets the year to `0001` which is not a leap year.

```julia
julia> Date("28 Feb",dateformat"d u")
0001-02-28

```

Not sure if there’s an easy way around this?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 25, 2020, 5:22am UTC](https://discourse.julialang.org/t/how-to-parse-a-string-as-a-date-where-the-year-is-a-leap-one-if-the-year-is-not-specified-in-the-string/38176/3 "2020-04-25T05:22:59Z")

</div>

There is

```julia
julia> Dates.parse_components("29 Feb", dateformat"d u")
2-element Array{Any,1}:
 29 days
 2 months

```
