cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2220
Views
5
Helpful
2
Replies

UCCX Scripting - Time Calculation

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

1 Accepted Solution

Accepted Solutions

Anthony Holloway
Cisco Employee
Cisco Employee

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

View solution in original post

2 Replies 2

Anthony Holloway
Cisco Employee
Cisco Employee

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

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

Getting Started

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: