# Named Query Between Dates DateTime Type

**URL:** <https://forum.inductiveautomation.com/t/named-query-between-dates-datetime-type/92957>\
**Category:** Ignition\
**Tags:** namedqueries, database, ignition81\
**Created:** [July 9, 2024, 2:41pm UTC](https://forum.inductiveautomation.com/t/named-query-between-dates-datetime-type/92957 "2024-07-09T14:41:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [July 9, 2024, 2:41pm UTC](https://forum.inductiveautomation.com/t/named-query-between-dates-datetime-type/92957/1 "2024-07-09T14:41:26Z")

</div>

Trying to create a named query for values between two dates. If I have 2 `DateTime` parameters, can I use them directly with the SQL statement, or do I need to do something to match the `datetime` type of the MS SQL table?

```python
SELECT t_stamp, val FROM Data
WHERE ( tag_id = :tag_name ) AND ( t_stamp BETWEEN :date_past AND :date_present )

```

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [July 9, 2024, 2:50pm UTC](https://forum.inductiveautomation.com/t/named-query-between-dates-datetime-type/92957/2 "2024-07-09T14:50:58Z")

</div>

That should work. Are you getting any errors or no data at all? If no data at all, are you sure tag\_id and tag\_name are equivalent....id's are usually numbers.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [July 9, 2024, 2:52pm UTC](https://forum.inductiveautomation.com/t/named-query-between-dates-datetime-type/92957/3 "2024-07-09T14:52:59Z")

</div>

It's a custom table. I don't have connection to the database at the moment, I was just curious about the difference between the datatypes

---

<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:** [July 9, 2024, 4:30pm UTC](https://forum.inductiveautomation.com/t/named-query-between-dates-datetime-type/92957/4 "2024-07-09T16:30:21Z")

</div>

The column type in the database should be `datetime2` for best results. If just the `datetime` column type, it'll work, but you generally have to run the database and gateway in the same time zone, and look out for time zone issues. (Run gateway and DB in UTC for best results with `datetime`.)
