# How to get best from string dateformat to yyyy-mm-dd

**URL:** <https://discourse.julialang.org/t/how-to-get-best-from-string-dateformat-to-yyyy-mm-dd/7106>\
**Category:** General Usage\
**Created:** [November 16, 2017, 6:50pm UTC](https://discourse.julialang.org/t/how-to-get-best-from-string-dateformat-to-yyyy-mm-dd/7106 "2017-11-16T18:50:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IljaK91](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iljak91/32/44301_2.png) [@IljaK91](https://discourse.julialang.org/u/IljaK91)\
**Post date:** [November 16, 2017, 6:50pm UTC](https://discourse.julialang.org/t/how-to-get-best-from-string-dateformat-to-yyyy-mm-dd/7106/1 "2017-11-16T18:50:28Z")

</div>

I have the following date format: “November 10, 2017, 01:15:58 PM” and want to change it to a more standard “yyyy-mm-dd”. Is there any smart way to go about it?

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [November 16, 2017, 7:05pm UTC](https://discourse.julialang.org/t/how-to-get-best-from-string-dateformat-to-yyyy-mm-dd/7106/2 "2017-11-16T19:05:04Z")

</div>

You could do this

```julia
function datereformat(str)
    if str[end-1:end] == "AM"
        dt = DateTime(str, dateformat"UUUU dd, yyyy, HH:MM:SS \A\M")
    else
        dt = DateTime(str, dateformat"UUUU dd, yyyy, HH:MM:SS \P\M")
    end
    return Dates.format(dt, dateformat"yyyy-mm-dd")
end

```
