# Selecting Records in SQL database with DATE

**URL:** <https://forum.inductiveautomation.com/t/selecting-records-in-sql-database-with-date/61839>\
**Category:** Ignition\
**Created:** [July 13, 2022, 11:14am UTC](https://forum.inductiveautomation.com/t/selecting-records-in-sql-database-with-date/61839 "2022-07-13T11:14:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven.rehnborg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.rehnborg/32/4952_2.png) [@steven.rehnborg](https://forum.inductiveautomation.com/u/steven.rehnborg)\
**Post date:** [July 13, 2022, 11:14am UTC](https://forum.inductiveautomation.com/t/selecting-records-in-sql-database-with-date/61839/1 "2022-07-13T11:14:47Z")

</div>

I am getting the following “ERROR: Conversion failed when converting date and/or time from character string.” when I attempt to select records from SQLExpress database based on the date. Specifically, I only want records that were added in the last 24 hours.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/5/8569c703a23898a94f58a5ff28a813e14d2a7b59.png)

I know I am missing something basic, but I haven’t determined a solution. My report seems to be displaying the entire database that began in July 2015 which is thousands of records if I am not selecting by date.

StartDate and EndDate are both Date type and .Time\_Stamp is also a datetime format in the database.

---

<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:** [July 13, 2022, 11:42am UTC](https://forum.inductiveautomation.com/t/selecting-records-in-sql-database-with-date/61839/2 "2022-07-13T11:42:43Z")

</div>

EDIT: Although I should be asking what version of Ignition.

Try putting in question marks and put the parameters below.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/c/0c2e7b9cad3673cc21ead0c32baf10326d43e300.png)

---

<div class="post-metadata">

**Author:** ![steven.rehnborg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.rehnborg/32/4952_2.png) [@steven.rehnborg](https://forum.inductiveautomation.com/u/steven.rehnborg)\
**Post date:** [July 13, 2022, 12:33pm UTC](https://forum.inductiveautomation.com/t/selecting-records-in-sql-database-with-date/61839/3 "2022-07-13T12:33:36Z")

</div>

I will try that. I went to an SQL function:

[Interval].Time\_Stamp between (select dateadd(hour, -24, getdate())) and (select dateadd(hour, +0, getdate()));

that seems to work though…I’m interested in trying your solution.

---

<div class="post-metadata">

**Author:** ![steven.rehnborg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.rehnborg/32/4952_2.png) [@steven.rehnborg](https://forum.inductiveautomation.com/u/steven.rehnborg)\
**Post date:** [July 13, 2022, 12:37pm UTC](https://forum.inductiveautomation.com/t/selecting-records-in-sql-database-with-date/61839/4 "2022-07-13T12:37:04Z")

</div>

It does work as well! The ? for the parameters is new to me. I haven’t used the parameters in my report queries before. Thanks!
