# String to Date

**URL:** <https://discourse.julialang.org/t/string-to-date/79741>\
**Category:** New to Julia\
**Tags:** dates\
**Created:** [April 20, 2022, 2:30pm UTC](https://discourse.julialang.org/t/string-to-date/79741 "2022-04-20T14:30:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gjh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gjh/32/31762_2.png) [@gjh](https://discourse.julialang.org/u/gjh)\
**Post date:** [April 20, 2022, 2:30pm UTC](https://discourse.julialang.org/t/string-to-date/79741/1 "2022-04-20T14:30:47Z")

</div>

Thank you for any help with this. When I convert this string to Date I get the below format. What am I doing wrong? Why can’t I get “yyyy-mm-dd”? Thank you!

using Dates, DataFrames  
id = [1, 2, 3, 4, 5]  
bday = [“8/23/62”, “12/26/66”, “1/17/62”, “12/30/61”, “12/13/62”]  
df = DataFrame(id=id, bday=bday)

df.bday = Date.(df.bday, “mm/dd/yy”)

5-element Vector{Date}:  
0062-08-23  
0066-12-26  
0062-01-17  
0061-12-30  
0062-12-13

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [April 20, 2022, 2:42pm UTC](https://discourse.julialang.org/t/string-to-date/79741/2 "2022-04-20T14:42:22Z")

</div>

Probably because 62 is parsed as year 62. You can do this (I skipped the df part)

```julia
Date.(bday, "mm/dd/yy") .+ Year(1900)

```

---

<div class="post-metadata">

**Author:** ![gjh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gjh/32/31762_2.png) [@gjh](https://discourse.julialang.org/u/gjh)\
**Post date:** [April 20, 2022, 3:48pm UTC](https://discourse.julialang.org/t/string-to-date/79741/3 "2022-04-20T15:48:48Z")

</div>

Thanks, it works but for dates that are \> 12/31/1999.

---

<div class="post-metadata">

**Author:** ![gjh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gjh/32/31762_2.png) [@gjh](https://discourse.julialang.org/u/gjh)\
**Post date:** [April 20, 2022, 4:13pm UTC](https://discourse.julialang.org/t/string-to-date/79741/4 "2022-04-20T16:13:26Z")

</div>

This was useful. Sorry that I did not find it before posting the question.

> [@Parsing a CSV file with 2-digit year](https://discourse.julialang.org/t/parsing-a-csv-file-with-2-digit-year/14876):
>
> I have a file with dates formatted like this: 5/7/10 2:11 for the date 2010-5-7 and the time 2:11 am. I’m having the hardest time getting that read in properly. I’m trying something like CSV.read("Data.csv", dateformat=dateformat"m/d/yy H:M"), but my dates are all formatted like this: 0010-5-7. I have two questions about this: a) What happened to the yy formatting in Julia 1.0? Am I mis-remembering this from Python? b) How can I read this data in with the right dates? Many thanks for any …

> <https://stackoverflow.com/questions/69371986/converting-2-digit-date-year-in-string-to-a-date-object>

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [April 20, 2022, 8:20pm UTC](https://discourse.julialang.org/t/string-to-date/79741/5 "2022-04-20T20:20:09Z")

</div>

Were there no long lasting lessons learned from dealing with this issue so much 20+ years ago?
