How to obtain difference btw 2 timestamp?

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

convert both timestamps to epoch using getTime() function and simply subtract them ie a-b . Result is in milliseconds.
Further there lookup at .
date extension which might help you

I already tried it. It works with but the following example didn’t
e.g. $extracts_refreshed_at.getTime() <== where $extracts_refreshed_at is _snaptype_localdatetime

Here is the error I am getting:
Failure: Unknown method: getTime, Reason: Object has an unknown type (org.joda.time.LocalDateTime), Resolution: Please check expression syntax

Let me check with Dev to see if it is limited to date-time only.

@aleung, it’s not pretty, but I think you can solve with DateTime.parse($extracts_refreshed_at.toString()).getTime()


thx, that works. On the similar note, anyway to get PST datetime with the function?

In the documentation, there is this example:

Creating and Formatting a Date in a Specific Timezone
Expression:’{“timeZone”:“PST”, “format”:“yyyy-MM-dd”}’)

Description: The expression will create the current date time in the PST timezone and format its output into a string in the form of yyyy-MM-dd.

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.{“timeZone”:“PST”, “format”:“yyyy-MM-dd”})

Can anyone help me to fix, datatype issue during date format conversion?

Date.parse($GTA_DATE_LAST_CHG.toString()).toLocaleDateTimeString({“format”:“dd/MM/YYYY HH:mm:ss”})

It gives result result 11/11/2009 17:03:37 but which has string datatype. But while loading into target facing an data type issue.

Instead of string datatype I need to convert as date-time datatype. but with the same above format.

Date.parse is already parsing it to a date object. Is that not good for you? What is the need for toLocaleDateTimeString again?

Am I missing something here?

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?

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()

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.

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)