09-27-2017 02:15 AM
Any idea how to obtain seconds, minutes, or hours between 2 timestamp?
Solved! Go to Solution.
09-27-2017 05:19 PM
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”})
11-30-2017 08:36 PM
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?
08-07-2019 10:17 AM
I’m not sure if something has changed, but his appears to not work anymore.
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()
08-07-2019 10:28 AM
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:
The Date.parse()
method parses dates and dates with times, not just time.
08-07-2019 04:01 PM
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.
And here are the values for the fields used:
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)