I am attempting to calculate a time difference between two DateTime objects. The first object is system.date.now(). The second object is giving me trouble. the second object is taken from a row in a dataset that was populated with a SQL query to a MySQL database.
current_datetime = system.date.now()
event_set_time = tbl.getValueAt(selrow, 'IG_Event_Set_time')
The customer wants to know the time difference in minutes (since_reset_time).
Something along the order of:
system.date.minutesBetween(current_datetime, event_set_time)
The event_set_time DateTime can actually be up to 10 days prior to current_datetime. The customer wants the since_reset_time in minutes. Every attempt I have made to calculate this number has resulted in some sort of datatype error.
What is the datatype of that table column ?
You can do tbl.getColumnType(tbl.getColumnIndex('IG_Event_Set_time'))
.
If the type of your column is string,
you’ll have to convert the time into date, one way is as below:
from java.util import Calendar
from java.text import SimpleDateFormat
Date format will vary.
time = SimpleDateFormat('yyyy-MM-dd HH:mm:ss').parse(time)
If the date format is date,
Can you post the Error ?
Hi. The column in mysql is a DATETIME. The column in the dataset is Date.
This is the closest I have come to getting this to work:
# Calculate Event Since Set Time
since_set_time_format = str(system.date.minutesBetween(event_set_time_raw,current_time_raw))
# since_set_time_format = current_datetime - event_set_datetime
since_set_str = str(since_set_time_format)

I am pretty sure there are more than 465 minutes between the two Datetimes
Amm, Something’s not right. I just checked mine with two different dates from SQL.
Can you please
print event_set_time_raw
print type(event_set_time_raw)
print current_time_raw
print type(current_time_raw)
Why not just use system.date.parse
?
That’s right !! Sometime I can only think non straightforward ways of solving problems
I shall try
101 print event_set_time_raw
102 print type(event_set_time_raw)
103 print current_time_raw
104 print type(current_time_raw)
returns:
Traceback (most recent call last):
File “event:mouseReleased”, line 2, in
File “”, line 102, in ShowDetails
TypeError: ‘unicode’ object is not callable
I shall try:
‘’’
current_time_parse = system.date.parse(current_time_raw)
event_set_time_raw = tbl.getValueAt(selrow, ‘IG_Event_Set_Time’)
event_set_time_parse = system.date.parse(event_set_time_raw)
since_set_time_test = str(system.date.minutesBetween(event_set_time_parse,current_time_parse))
Uploading seems to be not working for me today. The result is:
Set 2020-06-04 05:51:07
Since Set (min) 1021
I ran the script at 2020-07-04 07:28:03