cancel
Showing results for 
Search instead for 
Did you mean: 

How to obtain difference btw 2 timestamp?

aleung
Contributor III

Any idea how to obtain seconds, minutes, or hours between 2 timestamp?

1 ACCEPTED SOLUTION

In the above example just dont use the quotes, instead send as JSON object!! Otherwise you will get the warning from the platform at runtime.

Date.now().toLocaleDateString({“timeZone”:“PST”, “format”:“yyyy-MM-dd”})

View solution in original post

13 REPLIES 13

Yes,commonly SnapLogic giving there own format 2009-11-11T00:17:03.000 with additionally I need to convert into this format 11/11/2009 17:03:37 as same date-time datatype. For format conversion I am using toLocaleDateTimeString.

Is there is any other way to available for date conversion? MM/DD/YYYY HH:24:mm:ss from date-time object?

shane
New Contributor II

I’m not sure if something has changed, but his appears to not work anymore.
55%20AM

It appears that the object returned from DateTime.parse() doesn’t contain a getTime() method.

This leaves me with the same question that started this thread. Any idea how to obtain seconds, minutes, or hours between 2 timestamp?

I am stuck doing something that seems ‘hacky’ (but it works):
Date.parse('01/01/2019 ’ + $start_time).getTime()

tstack
Former Employee

Are you sure $end_time is a parseable date string? If the parse fails, a NaN is returned which is a Double internally. Sorry that’s not more clear.

You can move the cursor over to parse and $end_time to see what their values are. For example, the following shows the result of the parse is NaN with the same error message that you got:

image

The Date.parse() method parses dates and dates with times, not just time.

shane
New Contributor II

I see that the screenshot I posted was showing the Date.parse() not the DateTime.parse(), however I assure you that is where that error came from.

28%20PM
And here are the values for the fields used:
03%20PM
Please feel free to try using DateTime.parse().getTime() and see if it works but it does not for me.

Also a note to all doing time comparisons, you have to be weary of only having a timestamps but the dates may cross days. This works using the ‘hard-coded’ date string and Date.parse() but still seems a bit hacky for me:

(Date.parse('01/02/2019 ' + $end_time).getTime() >= Date.parse('01/02/2019 ' + $start_time).getTime()) ? ((Date.parse('01/02/2019 ' + $end_time).getTime() - Date.parse('01/02/2019 ' + $start_time).getTime()) / 1000) : ((Date.parse('01/02/2019 ' + $end_time).getTime() - Date.parse('01/01/2019 ' + $start_time).getTime()) / 1000)