# Named Queries/DateTime

**URL:** <https://forum.inductiveautomation.com/t/named-queries-datetime/53851>\
**Category:** Ignition\
**Created:** [December 7, 2021, 6:20pm UTC](https://forum.inductiveautomation.com/t/named-queries-datetime/53851 "2021-12-07T18:20:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew.Meronek](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@Andrew.Meronek](https://forum.inductiveautomation.com/u/Andrew.Meronek)\
**Post date:** [December 7, 2021, 6:20pm UTC](https://forum.inductiveautomation.com/t/named-queries-datetime/53851/1 "2021-12-07T18:20:11Z")

</div>

I am scratching my head at this, which returns no results even when I copy and paste the literal epoch date number into :Date\_Time in the Named Query “testing” window.

SELECT Date\_Time, :Date\_Time  
FROM Test\_Data  
WHERE Date\_Time = :Date\_Time

This should return two identical columns with the same Date\_Time I selected. Is Ignition changing the data somehow? Or is there another angle I need to consider?

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [December 7, 2021, 6:40pm UTC](https://forum.inductiveautomation.com/t/named-queries-datetime/53851/2 "2021-12-07T18:40:32Z")

</div>

This may be something I’m missing, but can you explain `:Date_Time` in your `SELECT` statement? Usually you have the parameter in the `WHERE` clause…

---

<div class="post-metadata">

**Author:** ![awaege1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/awaege1/32/28922_2.png) [@awaege1](https://forum.inductiveautomation.com/u/awaege1)\
**Post date:** [December 7, 2021, 7:20pm UTC](https://forum.inductiveautomation.com/t/named-queries-datetime/53851/3 "2021-12-07T19:20:54Z")

</div>

By using `:Date_Time` in your SELECT statement you are essentially saying this (I’ll use today’s date as the input)

```auto
SELECT Date_Time, 12/7/2021
FROM Test_Data
WHERE Date_Time = 12/7/2021

```

To do what you want, just do something like the following:

```auto
SELECT
   Date_Time AS date1,
   Date_Time AS date2,
FROM Test_Data
WHERE Date_Time = :Date_Time

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 7, 2021, 9:04pm UTC](https://forum.inductiveautomation.com/t/named-queries-datetime/53851/4 "2021-12-07T21:04:16Z")

</div>

~~You made no mention of what results you got. (I suspect nothing returned).~~  
EDIT: Sorry, reread you post, and you did say. Time for more coffee…

Most databases have datetime columns to millisecond precision. Consider truncating your Date\_Time column to seconds in your query.

You will likely have to change this to fit your db.

```sql
SELECT TRUNC(Date_Time, 'SECOND'), :Date_Time
FROM Test_Data
WHERE TRUNC(Date_Time, 'SECOND') = :Date_Time

```

---

<div class="post-metadata">

**Author:** ![Andrew.Meronek](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@Andrew.Meronek](https://forum.inductiveautomation.com/u/Andrew.Meronek)\
**Post date:** [December 7, 2021, 9:12pm UTC](https://forum.inductiveautomation.com/t/named-queries-datetime/53851/5 "2021-12-07T21:12:59Z")

</div>

Ah, yes my database stores datetime to millisecond precision. So then, does Ignition strip that somewhere? I know that (for example) in a Perspective table I can actually show the date as the epoch number instead of human-readable text by changing the column render - and at that point milliseconds are still there.

---

<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:** [December 7, 2021, 9:22pm UTC](https://forum.inductiveautomation.com/t/named-queries-datetime/53851/6 "2021-12-07T21:22:31Z")

</div>

Ignition generally does not strip milliseconds anywhere.

---

<div class="post-metadata">

**Author:** ![Andrew.Meronek](https://avatars.discourse-cdn.com/v4/letter/a/a9a28c/32.png) [@Andrew.Meronek](https://forum.inductiveautomation.com/u/Andrew.Meronek)\
**Post date:** [December 8, 2021, 4:30pm UTC](https://forum.inductiveautomation.com/t/named-queries-datetime/53851/8 "2021-12-08T16:30:57Z")

</div>

Phew! Figured it out. No millisecond truncation; I had to use DATEDIFF instead of = or LIKE in the WHERE clause:

SELECT Date\_Time, :Date\_Time  
FROM Test\_Data  
WHERE DATEDIFF(second, Date\_Time, :Date\_Time) = 0
