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!
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))
Thanks for the reply - unfortunately the first line gives the following error:
"TypeError: strptime(): 1st arg can't be coerced to String"
Can you share your code for more details?
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:
The setExecutionTime expects 1 timestamp parameter.
Are you sure this returns a time stamp databasePruningConfiguration.getExecutionTime(), you can show the code
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
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
d = system.date.now()
toMS = system.date.toMillis(d)
ts = java.sql.Timestamp(toMS)
Those 2 lines got it working, thank you!!