# Expression tag for UTC

**URL:** <https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054>\
**Category:** Ignition\
**Created:** [March 28, 2024, 8:42pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054 "2024-03-28T20:42:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [March 28, 2024, 8:42pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054/1 "2024-03-28T20:42:44Z")

</div>

Is there a simple expression that gets the UTC time from whatever the time is locally on the gateway?

My now() returns eastern time.  
Planning to use an expression tag for the UTC time in a transaction group.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 28, 2024, 8:46pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054/2 "2024-03-28T20:46:48Z")

</div>

Java date/time objects, as used in Ignition, are always UTC under the hood. They **look** like they are in some timezone when displayed/printed/stringified.

Just pass the date object to whatever needs it. That's it.

Worry about timezones when **parsing** user input, and **displaying** to a user. Full stop.

---

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [March 28, 2024, 8:47pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054/3 "2024-03-28T20:47:37Z")

</div>

What do I put in the expression for the expression tag?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 28, 2024, 8:48pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054/4 "2024-03-28T20:48:43Z")

</div>

Why do you need an expression tag for a transaction group? Just use an expression item within the transaction group, with `now(0)`.

Or just use the builtin feature of transaction groups to populate a timestamp column. (Make sure that column is timezone-aware--the default may not be.)

---

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [March 28, 2024, 8:49pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054/5 "2024-03-28T20:49:16Z")

</div>

The time will be in eastern in the table.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 28, 2024, 8:51pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054/6 "2024-03-28T20:51:09Z")

</div>

So, an MS SQL datetime column? Use datetime2 instead.

---

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [March 28, 2024, 8:55pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054/7 "2024-03-28T20:55:15Z")

</div>

I don't see datetime2 as an option in the transaction groups or the tag.

I am not permitted to change the gateway datatype for datetimes from datetime to datetime2.

* * *

I was hoping for something like:  
dateFormat(now(), "UTC")

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 28, 2024, 9:02pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054/8 "2024-03-28T21:02:48Z")

</div>

You mean the database datatype?

In that case, your best bet is to add a utc timezone property to the database connection properties and run the gateway itself in UTC.

If you cannot do that, you will likely have to use java's LocalDateTime in a script to present `now()` in UTC, which you will have to hand to the DB as a string. Not sure you can do that with actual datetime columns in a transaction group.

Your comment about permission means that whoever you work for is handcuffing you. If they want UTC in a non-timezone-aware column in MS SQL Server, and not have everyone go through their [expletive] to get to their elbow, they need to run the database and the gateway in UTC.

---

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [March 28, 2024, 9:08pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054/9 "2024-03-28T21:08:11Z")

</div>

I agree.

I need a tag for now though since I don't have permission to switch the gateway to timezone aware or UTC.  
Really thought this would work, but it did not:  
dateArithmetic(now(),getTimezoneRawOffset((now()),'hour')

Will come back to it tomorrow.

---

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [April 1, 2024, 1:46pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054/10 "2024-04-01T13:46:27Z")

</div>

I still have not found an expression that works.  
I don't like using dateArithmetic for this because if the gateway is switched, then that will be adding to UTC.  
I need something that expressly changes from one timezone to another.

```auto
 dateArithmetic(now(),if(dateIsDaylight({[.]nowTag}),4,5),'hour')

```

This is what I have for now though.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 1, 2024, 1:58pm UTC](https://forum.inductiveautomation.com/t/expression-tag-for-utc/88054/11 "2024-04-01T13:58:44Z")

</div>

Java's `LocalDateTime` and `ZonedDateTime` and `TimeZone` classes are not available anywhere in Ignition's expression language. You must use a script, and, perhaps, call it from `runScript()` or `objectScript()`.
