# SQL Problem with date variable

**URL:** <https://forum.inductiveautomation.com/t/sql-problem-with-date-variable/23160>\
**Category:** Ignition\
**Created:** [March 8, 2019, 1:59pm UTC](https://forum.inductiveautomation.com/t/sql-problem-with-date-variable/23160 "2019-03-08T13:59:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![keith.hyder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/keith.hyder/32/4909_2.png) [@keith.hyder](https://forum.inductiveautomation.com/u/keith.hyder)\
**Post date:** [March 8, 2019, 1:59pm UTC](https://forum.inductiveautomation.com/t/sql-problem-with-date-variable/23160/1 "2019-03-08T13:59:02Z")

</div>

Having issue with my date argument. Not sure what else to do to get it to accept.

```auto
date = system.date.now()
value1 = system.date.format(date, "yyyy/MM/dd HH:mm:ss")
system.gui.messageBox(value1)

query = ''' SELECT Rtrim(UID) AS [Row Number], RTRIM(PaintColor) AS [Paint Color], RTRIM(PaintPN) AS [Paint PN], RTRIM(StartTime) AS [Planed Start Time],
            RTRIM(StopTime) AS [Planed Stop Time], RTRIM(PlanDate) AS [Planed Date], RTRIM(EnteredBy) AS [Entered By],Shift 
            FROM SF_Paint_Schedule WHERE PlanDate >= ? '''         
                 
args = (value1)
data = system.db.runPrepQuery(query, args)

system.tag.write("[Client]Paint_Schedule",data)

```

Keep Getting this Error:

Traceback (most recent call last):  
File “event:actionPerformed”, line 12, in   
java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value ‘2019/03/08 08:45:10’ into type: class [Ljava.lang.Object;  
caused by ClassCastException: Cannot coerce value ‘2019/03/08 08:45:10’ into type: class [Ljava.lang.Object;  
Ignition v7.9.10 (b2018112821)  
Java: Oracle Corporation 1.8.0\_201

Thanks in advance for taking a look

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 8, 2019, 2:02pm UTC](https://forum.inductiveautomation.com/t/sql-problem-with-date-variable/23160/2 "2019-03-08T14:02:00Z")

</div>

Try this instead

```auto
import datetime
date = datetime.datetime.now()

```

---

<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:** [March 8, 2019, 2:07pm UTC](https://forum.inductiveautomation.com/t/sql-problem-with-date-variable/23160/3 "2019-03-08T14:07:39Z")

</div>

When you are using parameter substitution, don’t convert your date to a string. JDBC will take care of it for you – that’s the point. Also, parentheses don’t make a tuple, commas do. It’s better to use square brackets to make a list for args.

```auto
args = [system.date.now()]

```

---

<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:** [March 8, 2019, 2:12pm UTC](https://forum.inductiveautomation.com/t/sql-problem-with-date-variable/23160/4 "2019-03-08T14:12:05Z")

</div>

> [@dkhayes117](#):
>
> import datetime

Consider always using Java's native Date and Calendar types instead of python's versions. Most usage of python's library objects within java subsystems invokes a complicated type cast.

---

<div class="post-metadata">

**Author:** ![keith.hyder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/keith.hyder/32/4909_2.png) [@keith.hyder](https://forum.inductiveautomation.com/u/keith.hyder)\
**Post date:** [March 8, 2019, 2:50pm UTC](https://forum.inductiveautomation.com/t/sql-problem-with-date-variable/23160/5 "2019-03-08T14:50:46Z")

</div>

Pturmel. Thank you again sir. You have been helpful to me many times in the past I appreciate it. I also want to thank you dkhayes117 for your contribution as well. I am working good now.
