# Convert spinner.dateValue to a sql timestamp

**URL:** <https://forum.inductiveautomation.com/t/convert-spinner-datevalue-to-a-sql-timestamp/72277>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [April 10, 2023, 10:47pm UTC](https://forum.inductiveautomation.com/t/convert-spinner-datevalue-to-a-sql-timestamp/72277 "2023-04-10T22:47:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![W\_Perkins](https://avatars.discourse-cdn.com/v4/letter/w/3ab097/32.png) [@W\_Perkins](https://forum.inductiveautomation.com/u/W_Perkins)\
**Post date:** [April 10, 2023, 10:48pm UTC](https://forum.inductiveautomation.com/t/convert-spinner-datevalue-to-a-sql-timestamp/72277/1 "2023-04-10T22:48:00Z")

</div>

I'm using a Vision Spinner component formatted to display DateTime. After the user enters a value I'm trying to send that value via an application to be stored as a sql Timestamp, but I get an error "1st arg can't be coerced to java.sql.Timestamp".

Anyone know how to convert the spinner.dateValue to a Timestamp before I send it? Thanks!

---

<div class="post-metadata">

**Author:** ![Priyanka.Khandge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/priyanka.khandge/32/35989_2.png) [@Priyanka.Khandge](https://forum.inductiveautomation.com/u/Priyanka.Khandge)\
**Post date:** [April 11, 2023, 12:30pm UTC](https://forum.inductiveautomation.com/t/convert-spinner-datevalue-to-a-sql-timestamp/72277/2 "2023-04-11T12:30:15Z")

</div>

Try this way,

from datetime import datetime  
from time import strptime, mktime

Date = strptime(event.source.parent.getComponent('spinner').dateValue, '%d.%m.%Y %H:%M:%S')  
date = datetime.fromtimestamp(mktime(Date))

---

<div class="post-metadata">

**Author:** ![W\_Perkins](https://avatars.discourse-cdn.com/v4/letter/w/3ab097/32.png) [@W\_Perkins](https://forum.inductiveautomation.com/u/W_Perkins)\
**Post date:** [April 11, 2023, 1:02pm UTC](https://forum.inductiveautomation.com/t/convert-spinner-datevalue-to-a-sql-timestamp/72277/3 "2023-04-11T13:02:58Z")

</div>

Thanks for the reply - unfortunately the first line gives the following error:  
"TypeError: strptime(): 1st arg can't be coerced to String"

---

<div class="post-metadata">

**Author:** ![Priyanka.Khandge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/priyanka.khandge/32/35989_2.png) [@Priyanka.Khandge](https://forum.inductiveautomation.com/u/Priyanka.Khandge)\
**Post date:** [April 11, 2023, 1:04pm UTC](https://forum.inductiveautomation.com/t/convert-spinner-datevalue-to-a-sql-timestamp/72277/4 "2023-04-11T13:04:21Z")

</div>

Can you share your code for more details?

---

<div class="post-metadata">

**Author:** ![W\_Perkins](https://avatars.discourse-cdn.com/v4/letter/w/3ab097/32.png) [@W\_Perkins](https://forum.inductiveautomation.com/u/W_Perkins)\
**Post date:** [April 11, 2023, 1:13pm UTC](https://forum.inductiveautomation.com/t/convert-spinner-datevalue-to-a-sql-timestamp/72277/5 "2023-04-11T13:13:30Z")

</div>

During the vision window internalFrameOpen script, it fills the spinner value with this code line: The getExecutionTime() returns a timestamp value.  
system.gui.getParentWindow(event).getComponentForPath('Root Container.spnTargetTime').dateValue = databasePruningConfiguration.getExecutionTime()

This works correctly and displays the current timestamp value in the spinner.

After the user views/edits the time value and any other parameters, a save button calls code to save all values, including this line to store the time:  
databasePruningConfiguration.setExecutionTime(event.source.parent.getComponent('spnTargetTime').dateValue)

The setExecutionTime expects 1 timestamp parameter.

---

<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 11, 2023, 1:19pm UTC](https://forum.inductiveautomation.com/t/convert-spinner-datevalue-to-a-sql-timestamp/72277/6 "2023-04-11T13:19:25Z")

</div>

1. Are you sure this returns a time stamp databasePruningConfiguration.getExecutionTime(), you can show the code

2. Is it supposed to? The Value(Date) property of the spinner is a Date object, not a timestamp, but timestamp is a subclass of java.util.Date, so after that I guess you must use the timestamp

3. As long as what you are trying to convert to a java.sql.Timestamp is a java.util.Date or similar you can try to fit what I have here below as an example of converting to java.sql.Timestamp

```auto
import java.sql.Timestamp

d = system.date.now()
toMS = system.date.toMillis(d)
ts = java.sql.Timestamp(toMS)
print ts

```

---

<div class="post-metadata">

**Author:** ![W\_Perkins](https://avatars.discourse-cdn.com/v4/letter/w/3ab097/32.png) [@W\_Perkins](https://forum.inductiveautomation.com/u/W_Perkins)\
**Post date:** [April 11, 2023, 1:24pm UTC](https://forum.inductiveautomation.com/t/convert-spinner-datevalue-to-a-sql-timestamp/72277/7 "2023-04-11T13:24:57Z")

</div>

Those 2 lines got it working, thank you!!
