We want to subtract two dates in our Jython script and find out how many days have passed. Also, we would like to convert a date to a string that we can pass back to SQL to update the tables.
We are assigining a variable in our script a date from a component. We assume this is a python date type. When we called strftime on the date object we get a type mismatch error.
The value you’re getting back from the calendar component is a java Date object. Python uses tuples of values to represent a date. (see docs.python.org/lib/module-time.html)
You can make a python date from a java date like this:
from time import *
date = event.source.parent.getComponent("Calendar").date
pyDate = localtime(date.time/1000)
So your code would look like this:
[code]from time import *
querydFill = event.source.parent.getComponent(‘calFillDate’).date
querydFill = localtime(querydFill.time/1000)
fpmi.db.runUpdateQuery(“UPDATE LookUpFermantationTanks SET ProjFillDate = ‘%s’ WHERE FERMTANKID = ‘%s’” % (strftime("%Y-%m-%d %H-%M-%S", querydFill), keyValue1), ‘LabSNB01’)[/code]
Or, you could have used fpmi.db.dateFormat to skip the whole Python date stuff, like this: