# How to convert Time in AM or PM

**URL:** <https://forum.dimagi.com/t/how-to-convert-time-in-am-or-pm/8256>\
**Category:** Users\
**Created:** [June 17, 2021, 2:19pm UTC](https://forum.dimagi.com/t/how-to-convert-time-in-am-or-pm/8256 "2021-06-17T14:19:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gurudayalsahu](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/gurudayalsahu/32/2834_2.png) [@gurudayalsahu](https://forum.dimagi.com/u/gurudayalsahu)\
**Post date:** [June 17, 2021, 2:19pm UTC](https://forum.dimagi.com/t/how-to-convert-time-in-am-or-pm/8256/1 "2021-06-17T14:19:16Z")

</div>

Hi,  
I was looking for the option to get the Time to be converted from 24 Hrs. format to 12 Hrs format along with AM or PM, so that the same can be displayed in in the mobile device through displaying text (Label or Text).  
I was referring the URL : [Calculations with Dates and Times - CommCare Public - CommCare Public](https://wiki.commcarehq.org/display/commcarepublic/Calculations+with+Dates+and+Times)

But, i am not getting the correct syntax.

Any further suggestion ?

Thanks and regards,  
Gurudayal Sahu

---

<div class="post-metadata">

**Author:** ![Shivam](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/s/ce73a5/32.png) [@Shivam](https://forum.dimagi.com/u/Shivam)\
**Post date:** [June 18, 2021, 4:31am UTC](https://forum.dimagi.com/t/how-to-convert-time-in-am-or-pm/8256/2 "2021-06-18T04:31:37Z")

</div>

Hi Gurudayal,

I think we might not have a function that would give you time in 12 hours format, but you can apply simple maths to get the same.  
Here are the steps

- Create a hidden value `hour_24` which would use the `format-date` function and save the current hour in 24-hour format. Use this calculate condition:

```auto
format-date(now(), '%H')

```

- Create another hidden value `hours_12` which would convert the above 24-hr format to 12-hr format. Use this calculate condition:

```auto
if(#form/hour_24 > 12, #form/hour_24 - 12, if(#form/hour_24 = 0, 12, #form/hour_24))

```

- Create another hidden value `am_pm` to store the am or pm text. Use this calculate condition:

```auto
if(#form/hour_24 > 11, "PM", "AM")

```

- Finally in your label's display text, simply use these hidden values to show the current time in 12-hr format. Assuming you'd want to show time in this format "HH:MM AM/PM" then simply add this to your label's display text:

```auto
Today: <output value="#form/hours_12" />:<output value='format-date(now(), "%M")'/> <output value="#form/am_pm" />

```

---

<div class="post-metadata">

**Author:** ![gurudayalsahu](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/gurudayalsahu/32/2834_2.png) [@gurudayalsahu](https://forum.dimagi.com/u/gurudayalsahu)\
**Post date:** [June 18, 2021, 9:35am UTC](https://forum.dimagi.com/t/how-to-convert-time-in-am-or-pm/8256/3 "2021-06-18T09:35:05Z")

</div>

Thanks, Shivam !

It worked. This is very helpful !

Thanks and regards,  
Gurudayal Sahu
