# SQL query 'WHERE' clause based on timestamp

**URL:** <https://forum.inductiveautomation.com/t/sql-query-where-clause-based-on-timestamp/26067>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [June 24, 2019, 9:33pm UTC](https://forum.inductiveautomation.com/t/sql-query-where-clause-based-on-timestamp/26067 "2019-06-24T21:33:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![asap13](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@asap13](https://forum.inductiveautomation.com/u/asap13)\
**Post date:** [June 24, 2019, 9:33pm UTC](https://forum.inductiveautomation.com/t/sql-query-where-clause-based-on-timestamp/26067/1 "2019-06-24T21:33:14Z")

</div>

Hi,  
I have a report query to MYSQL DB 8.0, similar to :  
Select \* from my\_table where t\_stamp between {StartDate} and {EndDate};

The {StartDate} and {EndDate} are report parameters of the DATE type  
.  
On the window where I use this report I have two Popup Calendar components.  
I bind the report parameters to Popup Calendar.Date properties.

my\_table.t\_stamp is MYSQL DateTime type “yyyy-dd-mm hh:mm:ss”.

What is the proper syntax to be in query for the following portion:  
where t\_stamp between {StartDate} and {EndDate} ?

Thank you for any response.

---

<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 25, 2019, 12:05am UTC](https://forum.inductiveautomation.com/t/sql-query-where-clause-based-on-timestamp/26067/2 "2019-06-25T00:05:07Z")

</div>

Don’t use curly brace substitutions. They need quotes in the SQL because they are really string conversions. Use ‘?’ substitutions instead – those pass actual date objects to the JDBC driver.

---

<div class="post-metadata">

**Author:** ![asap13](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@asap13](https://forum.inductiveautomation.com/u/asap13)\
**Post date:** [June 25, 2019, 8:12pm UTC](https://forum.inductiveautomation.com/t/sql-query-where-clause-based-on-timestamp/26067/3 "2019-06-25T20:12:53Z")

</div>

[Query problem.pdf](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f18488f8bd06edc00becaf90a5c164352131870e.pdf) (208.1 KB)  
Thank you for reply. I appreciate it.  
I got rid of the Error with your advice but I didn’t reach the goal.  
Could you look at the attachment. I provide snapshots for two tests. First time I use hard typed dates and the data is returned. The second time I try to use ‘StartDate’ and ‘EndDate’. The return is empty. What am I doing wrong?

---

<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 25, 2019, 8:19pm UTC](https://forum.inductiveautomation.com/t/sql-query-where-clause-based-on-timestamp/26067/4 "2019-06-25T20:19:43Z")

</div>

Put literal question marks, without quotes, where you are trying to put your start and end dates. Put your start and end date parameters in the expression boxes that appear for the question marks.
