# Proper DateTime format to insert into a DATETIME mySQL field

**URL:** <https://forum.inductiveautomation.com/t/proper-datetime-format-to-insert-into-a-datetime-mysql-field/113712>\
**Category:** General Discussion\
**Created:** [February 3, 2026, 2:13am UTC](https://forum.inductiveautomation.com/t/proper-datetime-format-to-insert-into-a-datetime-mysql-field/113712 "2026-02-03T02:13:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![EDoepke](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@EDoepke](https://forum.inductiveautomation.com/u/EDoepke)\
**Post date:** [February 3, 2026, 2:13am UTC](https://forum.inductiveautomation.com/t/proper-datetime-format-to-insert-into-a-datetime-mysql-field/113712/1 "2026-02-03T02:13:55Z")

</div>

I am trying to log data on a daily basis, but for the previous day. I have created a Named Query to utilize a parameter for the date (which will be set to 1 day previous). When I “test” the named query and type in a date of “2026-02-02 00:15:00” it inserts into the mySQL table just fine.

When I try to pass anything into the named query, it fails. I have tried sending it an actual DateTime tagtype from Ignition as well as a formatted string. The numerical data inserts correctly, but my LogDateTime column in the DB has “NULL”.

I am relatively new to mySQL, so kinda flustered. Since this is a once a day logged event, I would love to be able to just set up the LogDateTime with an initial value of same time but 1 day previous, but haven’t figured that part out.

Any guidance is greatly appreciated!

---

<div class="post-metadata">

**Author:** ![EDoepke](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@EDoepke](https://forum.inductiveautomation.com/u/EDoepke)\
**Post date:** [February 3, 2026, 2:18am UTC](https://forum.inductiveautomation.com/t/proper-datetime-format-to-insert-into-a-datetime-mysql-field/113712/2 "2026-02-03T02:18:31Z")

</div>

I figured out how to properly set initial DATETIME field in DB correctly. Just took some more digging. Thanks!

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [February 3, 2026, 4:39am UTC](https://forum.inductiveautomation.com/t/proper-datetime-format-to-insert-into-a-datetime-mysql-field/113712/3 "2026-02-03T04:39:45Z")

</div>

Good to know you fixed it, so_mehow._ Would be good for _others_ to know how, to help them as well.

Also, with datetimes, be cautious of daylight savings or timezones in general, especially if you’re in a TZ with dst or are working with multiple gateways/dbs across multiple timezones. If you're storing datetimes without timezone info in the DB, then they should be stored in UTC

---

<div class="post-metadata">

**Author:** ![EDoepke](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@EDoepke](https://forum.inductiveautomation.com/u/EDoepke)\
**Post date:** [February 3, 2026, 7:46pm UTC](https://forum.inductiveautomation.com/t/proper-datetime-format-to-insert-into-a-datetime-mysql-field/113712/4 "2026-02-03T19:46:32Z")

</div>

I set the Default value for the datetime field to (now() - interval 1 day). This sets the timestamp to 24 hours previous to when the data is logged, which would essentially give me the proper date value for the data.

---

<div class="post-metadata">

**Author:** ![Lynn\_Martineau](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@Lynn\_Martineau](https://forum.inductiveautomation.com/u/Lynn_Martineau)\
**Post date:** [April 7, 2026, 8:50pm UTC](https://forum.inductiveautomation.com/t/proper-datetime-format-to-insert-into-a-datetime-mysql-field/113712/5 "2026-04-07T20:50:58Z")

</div>

I give up - how is

> [@EDoepke](#):
>
> (now() - interval 1 day)

the correct date for the data?  
I can’t think of a case where that’s truthful.  
If I need to report the day before an event, I would subtract a day for display or report but store the true event timestamp.

---

<div class="post-metadata">

**Author:** ![tgarrison](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tgarrison/32/80965_2.png) [@tgarrison](https://forum.inductiveautomation.com/u/tgarrison)\
**Post date:** [April 8, 2026, 6:33pm UTC](https://forum.inductiveautomation.com/t/proper-datetime-format-to-insert-into-a-datetime-mysql-field/113712/6 "2026-04-08T18:33:15Z")

</div>

He's likely collecting yesterdays data just after midnight. So he wants to store against yesterday. It's a common practice.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 8, 2026, 6:40pm UTC](https://forum.inductiveautomation.com/t/proper-datetime-format-to-insert-into-a-datetime-mysql-field/113712/7 "2026-04-08T18:40:06Z")

</div>

Sure could be, but setting it as a default value for the created at column is a bad idea insofar as the next person who has to troubleshoot it. You insert a row, insepect it without a created at column and now it says yestedray? The person is going to start checking the clocks of the client/server etc.

Calculate it and then INSERT via prep query, either via jython and `system.date.*` functions or directly in the INSERT text like

`INSERT INTO Table (LogDateTime) VALUES (now() - INTERVAL 1 DAY)`so that its obvious.

Don’t hide business logic in default values / triggers.

---

<div class="post-metadata">

**Author:** ![Lynn\_Martineau](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@Lynn\_Martineau](https://forum.inductiveautomation.com/u/Lynn_Martineau)\
**Post date:** [April 9, 2026, 5:08pm UTC](https://forum.inductiveautomation.com/t/proper-datetime-format-to-insert-into-a-datetime-mysql-field/113712/8 "2026-04-09T17:08:16Z")

</div>

Yes, it’s common practice to have scheduled batch processes to move data, but, those processes shouldn’t calculate (guess/estimate) when data events occurred. That timestamp is one additional field of data that goes along for the ride.
