# Ignition Min and Max Date From Dataset

**URL:** <https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499>\
**Category:** Ignition\
**Created:** [June 17, 2018, 10:24am UTC](https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499 "2018-06-17T10:24:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![john.keshecki](https://avatars.discourse-cdn.com/v4/letter/j/c57346/32.png) [@john.keshecki](https://forum.inductiveautomation.com/u/john.keshecki)\
**Post date:** [June 17, 2018, 10:24am UTC](https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499/1 "2018-06-17T10:24:34Z")

</div>

Does anyone know an easy way to get the min and max date values from a dataset with multiple columns, one column is datetime? I’m using Ignition version 7.8.5.

---

<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:** [June 17, 2018, 11:26pm UTC](https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499/2 "2018-06-17T23:26:21Z")

</div>

Have you tried the [minDate](https://docs.inductiveautomation.com/display/DOC/minDate) and [maxDate](https://docs.inductiveautomation.com/display/DOC/maxDate) expression functions?

---

<div class="post-metadata">

**Author:** ![john.keshecki](https://avatars.discourse-cdn.com/v4/letter/j/c57346/32.png) [@john.keshecki](https://forum.inductiveautomation.com/u/john.keshecki)\
**Post date:** [June 18, 2018, 10:16am UTC](https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499/3 "2018-06-18T10:16:18Z")

</div>

Yeah, I get:  
“NameError: name ‘minDate’ is not defined.”

Do I need to import anything before using it? Or is it not available on the version I’m using (7.8.5)?

---

<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:** [June 18, 2018, 12:14pm UTC](https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499/4 "2018-06-18T12:14:29Z")

</div>

These are expression functions, to be used in a binding. If you are scripting, iterate through the dataset to build a list from the timestamp column, then use python’s min and max functions. Something like this:

```auto
timestamps = [ds.getValueAt(r, 't_stamp') for r in range(ds.rowCount)]
print min(timestamps), max(timestamps)

```

---

<div class="post-metadata">

**Author:** ![john.keshecki](https://avatars.discourse-cdn.com/v4/letter/j/c57346/32.png) [@john.keshecki](https://forum.inductiveautomation.com/u/john.keshecki)\
**Post date:** [June 18, 2018, 7:09pm UTC](https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499/5 "2018-06-18T19:09:32Z")

</div>

That worked, thank you!

---

<div class="post-metadata">

**Author:** ![zachary.roisum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zachary.roisum/32/42809_2.png) [@zachary.roisum](https://forum.inductiveautomation.com/u/zachary.roisum)\
**Post date:** [November 19, 2021, 12:26pm UTC](https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499/6 "2021-11-19T12:26:42Z")

</div>

Curious if you had a time zone conversion problem when using this script. It seems like the actual value stored in SQL in other scripts is in UDT not my gateway or session time zone. When I read back from the database often the local time zone will be applied, but this script does not adjust for the gateway/session time zone. Any guess on an easy way to fix this, or do I need to expand the script to get time zone and then add/subtract that value from the returned date/time?

---

<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:** [November 19, 2021, 2:10pm UTC](https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499/7 "2021-11-19T14:10:08Z")

</div>

If by SQL you mean MS SQL Server, then yes, you are [expletive]. Its timezone-aware column type, DATETIME2, is not generically supported by JDBC. So you must use DATETIME, which uses local time. Pretty much all other databases have a timezone-compatible column type that stores UTC under the hood and converts to and from the connection timezone on the fly. This behavior perfectly matches Java’s date/time functionality and “just works” with Ignition.

If you’ve ever wondered why Ignition’s Tag Historian uses a long integer (UTC milliseconds) for `t_stamp` instead of a proper timestamp column, now you know.

So:

- Use a timezone compatible column type in a competent DB (like `timestamptz` in PostgreSQL), or
- Run your MS SQL Server and your Ignition gateway in UTC–Java will do the rest.

---

<div class="post-metadata">

**Author:** ![cesma2000](https://avatars.discourse-cdn.com/v4/letter/c/c6cbf5/32.png) [@cesma2000](https://forum.inductiveautomation.com/u/cesma2000)\
**Post date:** [November 19, 2021, 3:34pm UTC](https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499/8 "2021-11-19T15:34:00Z")

</div>

Like said from **[pturmel]** first of all you need to verified your dateTime format to know what are you  
working on. Different DBMS work with different dateTime format.

---

<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:** [November 19, 2021, 3:46pm UTC](https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499/9 "2021-11-19T15:46:19Z")

</div>

DateTime formats should not matter, because datetimes should only go to databases as parameters, not as strings. (Value params in Named Queries or ‘?’ substitutions in “Prep” queries.)

---

<div class="post-metadata">

**Author:** ![zachary.roisum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zachary.roisum/32/42809_2.png) [@zachary.roisum](https://forum.inductiveautomation.com/u/zachary.roisum)\
**Post date:** [November 20, 2021, 2:26pm UTC](https://forum.inductiveautomation.com/t/ignition-min-and-max-date-from-dataset/18499/10 "2021-11-20T14:26:30Z")

</div>

Thanks, that explains the problem I’m running into.  
Earlier in troubleshooting I was able to get the datetime tag to display well because the gateway and database were on UTC, but the reports were not displaying in local time as those run on the gateway.  
This gives me some things to think about, this early in the project it might not be too difficult to change databases.
