# Inconsistent date types from MySQL Database in Perspective?

**URL:** <https://forum.inductiveautomation.com/t/inconsistent-date-types-from-mysql-database-in-perspective/34202>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 24, 2020, 3:44pm UTC](https://forum.inductiveautomation.com/t/inconsistent-date-types-from-mysql-database-in-perspective/34202 "2020-04-24T15:44:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 24, 2020, 3:44pm UTC](https://forum.inductiveautomation.com/t/inconsistent-date-types-from-mysql-database-in-perspective/34202/1 "2020-04-24T15:44:49Z")

</div>

I’m having a very difficult time figuring this out. In perspective, we have a function that after insert/update, we check that it worked. We do this based on type and values. With dates I like to use the native java.util.date that we get from date columns in MySQL and compare them to the java.util.date objects I get from date components.

I am getting an error from my function anytime I try to update a date column via perspective now though in my chrome console about mismatched types between the db and what I fed it -  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/88186cc900823c37c77425588c51d6cadd272021.png)

So in my select statement that’s running to check if the update worked, `SELECT lastStartDateSelected FROM listusers WHERE idx = 3047`. Here’s the short script I use to get the value/type for my check -

```auto
selectQuery = "SELECT %s FROM %s WHERE idx = %i"%(columnNames, tableName, idx)
	system.perspective.print("SELECT QUERY: " + str(selectQuery))
	results = system.dataset.toPyDataSet(system.db.runQuery(selectQuery))
	badResult = False
	for key in dictionary.keys():
		databaseValue = results[0][str(key)]
		dictionaryValue = dictionary[key]
		system.perspective.print("db Value: " + str(databaseValue))
		system.perspective.print("db Type: " + str(type(databaseValue)))
		system.perspective.print("dict value: " + str(dictionaryValue))
		system.perspective.print("dict type: " + str(type(dictionaryValue)))

```

Now here is the odd thing, running the very same select statement in the scripting console and doing type on it gives me a `java.util.date` which is what I expect, but for some reason, perspective calling this function and running the same exact query returns a `java.sql.timestamp` which ruins my comparisons. Any idea why this is and if it can be changed?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 24, 2020, 4:16pm UTC](https://forum.inductiveautomation.com/t/inconsistent-date-types-from-mysql-database-in-perspective/34202/2 "2020-04-24T16:16:49Z")

</div>

`java.sql.Timestamp` is a subclass of `java.util.Date` - it should work the same for comparison purposes:  
[https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/Timestamp.html](https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/Timestamp.html)

If you specifically need a date, you could convert it back pretty easily; check if `isinstance(java.sql.Timestamp)`, then convert it via `system.date.fromMillis(timestamp.time)`

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 24, 2020, 4:54pm UTC](https://forum.inductiveautomation.com/t/inconsistent-date-types-from-mysql-database-in-perspective/34202/3 "2020-04-24T16:54:23Z")

</div>

OK this does work. I know with Perspective all the scripts run on the gateway - is that what causes it to be a different type? Some different logic in the gateway with handling a date column vs running the same query via a client? This really threw me for a loop for a bit lol.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 24, 2020, 5:34pm UTC](https://forum.inductiveautomation.com/t/inconsistent-date-types-from-mysql-database-in-perspective/34202/4 "2020-04-24T17:34:29Z")

</div>

Yeah, we’re probably serializing to a Date directly before sending the results down to the client, but on the gateway you’re getting them directly.
