# Getting the current time in an expression

**URL:** <https://forum.inductiveautomation.com/t/getting-the-current-time-in-an-expression/15683>\
**Category:** Ignition\
**Created:** [October 17, 2017, 1:55am UTC](https://forum.inductiveautomation.com/t/getting-the-current-time-in-an-expression/15683 "2017-10-17T01:55:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CJVR](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@CJVR](https://forum.inductiveautomation.com/u/CJVR)\
**Post date:** [October 17, 2017, 1:55am UTC](https://forum.inductiveautomation.com/t/getting-the-current-time-in-an-expression/15683/1 "2017-10-17T01:55:32Z")

</div>

I have an expression for a custom message of an alarm that looks like this:

```auto
if(left({State}, 5) = "Clear"
,
"- '{name}' on '{displayPath}' went out of alarm at " + getHour12(now()) + ":" + getMinute(now()) + ":" + getSecond(now()) + " " + if(getAMorPM(now()) = 1, "PM", "AM") + "."
,
"- '{name}' on '{displayPath}' went into alarm at " + getHour12(now()) + ":" + getMinute(now()) + ":" + getSecond(now()) + " " + if(getAMorPM(now()) = 1, "PM", "AM") + ". " + "\n" +
" Drive Fault: " + {[.]LastFault} + " - " + {[.]LastFaultName})

```

I am doing this to include tag values in the email. This works great except when the minutes or seconds are less than ten. The time can end up looking something like this:

`4:5:2 PM`

Obviously, this does not look good. Is there a better way to grab the time part of now()? Is there a different way to do what I am doing?

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [October 17, 2017, 5:56am UTC](https://forum.inductiveautomation.com/t/getting-the-current-time-in-an-expression/15683/2 "2017-10-17T05:56:41Z")

</div>

[https://docs.inductiveautomation.com:8443/display/DOC78/dateFormat](https://docs.inductiveautomation.com:8443/display/DOC78/dateFormat) should do the trick

---

<div class="post-metadata">

**Author:** ![CJVR](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@CJVR](https://forum.inductiveautomation.com/u/CJVR)\
**Post date:** [October 17, 2017, 10:12am UTC](https://forum.inductiveautomation.com/t/getting-the-current-time-in-an-expression/15683/3 "2017-10-17T10:12:34Z")

</div>

Why did I not see that function?! Thanks.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [October 17, 2017, 2:58pm UTC](https://forum.inductiveautomation.com/t/getting-the-current-time-in-an-expression/15683/4 "2017-10-17T14:58:56Z")

</div>

Just for completeness, I’ll link the current version of the docs: [https://docs.inductiveautomation.com:8443/display/DOC79/dateFormat](https://docs.inductiveautomation.com:8443/display/DOC79/dateFormat)

In 7.9 we introduced a whole lot more date handling expression functions, which you can see in the left-hand column. Dealing with dates should be relatively easy now in both expressions and functions.
