# AM/PM in Date Format

**URL:** <https://discourse.julialang.org/t/am-pm-in-date-format/17356>\
**Category:** General Usage\
**Created:** [November 9, 2018, 5:07pm UTC](https://discourse.julialang.org/t/am-pm-in-date-format/17356 "2018-11-09T17:07:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MLackner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlackner/32/2789_2.png) [@MLackner](https://discourse.julialang.org/u/MLackner)\
**Post date:** [November 9, 2018, 5:07pm UTC](https://discourse.julialang.org/t/am-pm-in-date-format/17356/1 "2018-11-09T17:07:21Z")

</div>

Hi!

How do I get the am/pm information from a string to a DateTime?  
I’ve got the following string:

```julia
str = "11/7/2018 1:22:51 PM"

```

and want to parse it as a `DateTime`:

```julia
DateTime(str, dateformat"m/d/yyyy H:mm:ss ?")

```

Which character should I use for the PM?

---

<div class="post-metadata">

**Author:** ![shorty66](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shorty66/32/3254_2.png) [@shorty66](https://discourse.julialang.org/u/shorty66)\
**Post date:** [November 9, 2018, 5:09pm UTC](https://discourse.julialang.org/t/am-pm-in-date-format/17356/2 "2018-11-09T17:09:24Z")

</div>

This is currently unsupported.

Also see this issue: [23870](https://github.com/JuliaLang/julia/issues/23870)

---

<div class="post-metadata">

**Author:** ![MLackner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlackner/32/2789_2.png) [@MLackner](https://discourse.julialang.org/u/MLackner)\
**Post date:** [November 9, 2018, 5:28pm UTC](https://discourse.julialang.org/t/am-pm-in-date-format/17356/3 "2018-11-09T17:28:25Z")

</div>

Thanks!

Got it to work for my case with slight modifications

```julia
function parse_datetime_ampm(ds::String, fmt::DateFormat)::DateTime
    @show m = match(r"(\d{1,2}/\d{1,2}/\d{4}\s?\d{1,2}:\d{1,2}:\d{1,2})\s?(AM|PM)?"i, ds)
    dt = DateTime(m.captures[1], fmt) 
    ampm = m.captures[2]
    dt += (ampm != nothing && uppercase(ampm) == "PM" && Hour(dt).value != 12) ? Hour(12) : Hour(0)
end

```

---

<div class="post-metadata">

**Author:** ![staticfloat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/staticfloat/32/34_2.png) [@staticfloat](https://discourse.julialang.org/u/staticfloat)\
**Post date:** [October 8, 2019, 8:00am UTC](https://discourse.julialang.org/t/am-pm-in-date-format/17356/4 "2019-10-08T08:00:29Z")

</div>

Note that this has since been fixed in [https://github.com/JuliaLang/julia/pull/32308](https://github.com/JuliaLang/julia/pull/32308), and will appear in julia 1.3
