# Problems with date type in NamedQuery

**URL:** <https://forum.inductiveautomation.com/t/problems-with-date-type-in-namedquery/91402>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 5, 2024, 11:20am UTC](https://forum.inductiveautomation.com/t/problems-with-date-type-in-namedquery/91402 "2024-06-05T11:20:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [June 5, 2024, 11:20am UTC](https://forum.inductiveautomation.com/t/problems-with-date-type-in-namedquery/91402/1 "2024-06-05T11:20:52Z")

</div>

Hello!

I got a Named query with a timestamp

```python
...
 WHERE TM.timestamp BETWEEN ADD_MONTHS(TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS'), -12) AND TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS')
...
  WHERE TO_CHAR(TM.timestamp, 'YYYY') = TO_CHAR(TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY')
      AND TO_CHAR(TM.timestamp, 'IW') = TO_CHAR(TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS'), 'IW')
      AND TS.ORDEN_DNF IS NOT NULL
....

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/e/4e7f95066f91511fecabe14e10b1488b77998c7e.png)

2023-01-01

when I want to execute the query and use the parameter startdate  
as string it shows data, if I use Data Type DateTime, doesnt

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/a/ba210bedbf66fb913e45a6f9dc760538ce51e3ae.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 5, 2024, 11:34am UTC](https://forum.inductiveautomation.com/t/problems-with-date-type-in-namedquery/91402/2 "2024-06-05T11:34:52Z")

</div>

```python
...
  WHERE TO_CHAR(TM.timestamp, 'YYYY') = TO_CHAR(TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY')
      AND TO_CHAR(TM.timestamp, 'IW') = TO_CHAR(TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS'), 'IW')
      AND TS.ORDEN_DNF IS NOT NULL
....

```

This sort of thing will slow down your database queries. The query engine has to convert the timestamp column of every record in the table before it can do the comparison.

If the column datatype is set to DateTime then it can be indexed and searching by non-converted timestamp will be much, much faster.

Go to your database utility and check the datatype for the timestamp column. It should be DATETIME or BIGINT if using Ignition's t\_stamp format. Don't use string for dates except at the last moment before display.
