# 7.8.2 Report Module Datetime Issue for MS SQL

**URL:** <https://forum.inductiveautomation.com/t/7-8-2-report-module-datetime-issue-for-ms-sql/11462>\
**Category:** Ignition\
**Created:** [April 4, 2016, 8:33pm UTC](https://forum.inductiveautomation.com/t/7-8-2-report-module-datetime-issue-for-ms-sql/11462 "2016-04-04T20:33:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kykam](https://avatars.discourse-cdn.com/v4/letter/k/db5fbb/32.png) [@kykam](https://forum.inductiveautomation.com/u/kykam)\
**Post date:** [April 4, 2016, 8:33pm UTC](https://forum.inductiveautomation.com/t/7-8-2-report-module-datetime-issue-for-ms-sql/11462/1 "2016-04-04T20:33:22Z")

</div>

I’m trying to do a simple query based on time, but I am having no luck.

I’m using the defaults that are put in automatically for StartDate and EndDate.

In the Preview Window, I get the following format for StartDate:

```auto
2016-04-04 08:27:15
```

But, when I run the following query:

`SELECT * FROM tbl_turbineData
WHERE t_stamp > '{StartDate}'`

I get this date format, which MS SQL doesn’t like…

```auto
Mon Apr 04 08:29:22 EDT 2016
```

I usually get the following warning:

```auto
WARN: Simple Query could not be completedConversion failed when converting date and/or time from character string
```

Is there something that I’m missing?

---

<div class="post-metadata">

**Author:** ![rrdiggy76](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rrdiggy76/32/3741_2.png) [@rrdiggy76](https://forum.inductiveautomation.com/u/rrdiggy76)\
**Post date:** [April 4, 2016, 10:06pm UTC](https://forum.inductiveautomation.com/t/7-8-2-report-module-datetime-issue-for-ms-sql/11462/2 "2016-04-04T22:06:07Z")

</div>

I could be way off on this one, but here goes.

Firstly, if you want to use a parameter, in this case StartDate, try changing your SQL query to:

```auto
SELECT * FROM tbl_turbineData WHERE t_stamp > ?
```

The ‘?’ will unlock the Parameter 1 field below the query where you can now select {StartDate} from the defined Parameters (3rd icon down)

If you are still having problems with the SQL formatting of the date and depending on your t\_stamp field and SQL version, you may need to use the CAST (expression AS data\_type) Function.

I do and use the following to get all fields where the day was yesterday.

```auto
SELECT * FROM sometable WHERE CAST(date AS DATE) = CAST(GETDATE() - 1 AS DATE)
```

---

<div class="post-metadata">

**Author:** ![kykam](https://avatars.discourse-cdn.com/v4/letter/k/db5fbb/32.png) [@kykam](https://forum.inductiveautomation.com/u/kykam)\
**Post date:** [April 5, 2016, 12:06pm UTC](https://forum.inductiveautomation.com/t/7-8-2-report-module-datetime-issue-for-ms-sql/11462/3 "2016-04-05T12:06:07Z")

</div>

First solution helped. I had been trying this before, but I was under the Basic SQL Query, which doesn’t support that.

Thanks
