# Using datetime tags in an SQL Query

**URL:** <https://forum.inductiveautomation.com/t/using-datetime-tags-in-an-sql-query/8430>\
**Category:** Ignition\
**Created:** [May 9, 2014, 2:29pm UTC](https://forum.inductiveautomation.com/t/using-datetime-tags-in-an-sql-query/8430 "2014-05-09T14:29:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David.Doll](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@David.Doll](https://forum.inductiveautomation.com/u/David.Doll)\
**Post date:** [May 9, 2014, 2:29pm UTC](https://forum.inductiveautomation.com/t/using-datetime-tags-in-an-sql-query/8430/1 "2014-05-09T14:29:03Z")

</div>

I am trying to write a DB query to pull data based on a field value between two datetimes. I’m pulling the criteria datetime values from two datetime tags. I keep getting errors and can’t seem to hit the right combination of delimiters to identify the tag values as dates. See below:  
[attachment=1]Screen Shot 05-09-14 at 08.17 AM.PNG[/attachment]

And another attempt:  
[attachment=0]Screen Shot 05-09-14 at 08.19 AM.PNG[/attachment]

Any insight into the proper syntax or otherwise what I’m missing would be greatly appreciated.

David

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [May 9, 2014, 2:33pm UTC](https://forum.inductiveautomation.com/t/using-datetime-tags-in-an-sql-query/8430/2 "2014-05-09T14:33:27Z")

</div>

The Database Query Browser cannot reference tags like that. It just send text to the SQL Server (parsed by Ignition a little, such as to limit the number of records returned). To test this, create a Table component in a test window and set the binding of the Table.data to SQL Query and then paste this in. (Use the single quote syntax.)
