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 https://docs-snaplogic.atlassian.net/wiki/spaces/SD/pages/1439344/Date+Functions+and+Properties .
date extension which might help you

I already tried it. It works with Date.now().getTime() 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()

2 Likes

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

In the documentation, there is this example:

Creating and Formatting a Date in a Specific Timezone
Expression:
Date.now().toLocaleDateString(’{“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.

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

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?