08-03-2021 10:17 AM
I have a script where I obtain a string variable containing time and date in the format:
"2021-08-03T17:09:49.809Z"
T[now].toGMTString() returns a string in the format:
"3 Aug 2021 17:39:30 GMT"
With both variables as strings but in different formats, how can I easily subtract the current time (17:39) from the obtained time (17:09) in order to evaluate if said difference is more than 1 hour?
I'm not well versed with the Time/Date functions built into UCCX editor other than finding T[now] and then figuring out the .toGMTstring()
Here is what I am looking for in somewhat pseudocode:
calculatedTime = (Current Time - Obtained time)
if calculatedTime > 1 hour:
do stuff
Solved! Go to Solution.
08-06-2021 09:48 AM - edited 08-06-2021 10:38 AM
Here's one way to solve this
Variables
java.text.SimpleDateFormat formatter = null String obtained_time = "2021-08-03T17:09:49.809Z" Date last_seen = null
Script Steps
/* setup a date formatter for how we expect to see our input */ Set formatter = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") /* convert our input into a date object, using our formatter */ Set last_seen = formatter.parse(obtained_time) /* check if we saw it over an hour ago */ If (d[now].getTime() - last_seen.getTime() > 3600000) Then True /* it's been more than an hour */ False /* not quite long enough */
HTH
08-06-2021 09:48 AM - edited 08-06-2021 10:38 AM
Here's one way to solve this
Variables
java.text.SimpleDateFormat formatter = null String obtained_time = "2021-08-03T17:09:49.809Z" Date last_seen = null
Script Steps
/* setup a date formatter for how we expect to see our input */ Set formatter = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") /* convert our input into a date object, using our formatter */ Set last_seen = formatter.parse(obtained_time) /* check if we saw it over an hour ago */ If (d[now].getTime() - last_seen.getTime() > 3600000) Then True /* it's been more than an hour */ False /* not quite long enough */
HTH
08-06-2021 12:28 PM
I've seen your name on numerous other posts and was hoping you'd see mine - thank you! This is exactly what I needed and works perfectly
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: