In this blog, we shared in detail to use daysBetween(start date, end date) and date_diff(datepart, start date, end date) functions to compare 2 dates.
Another function relate to date is date_to_epoch(date).
date_to_epoch(date) converts a date value into Unix epoch seconds—i.e., the number of seconds elapsed since 00:00:00 UTC on January 1, 1970, so the result here is a number in seconds.
date_to_epoch() must take a toDate() or now() function as its first argument, sample:.
date_to_epoch(now()) or
date_to_epoch(toDate(CreatedDate, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")) or date_to_epoch(toDate(CreatedDate_sec_epoch))
-> the last 2 have similar result.
Sample result:
2024-02-26T14:10:21.000Z → 1,708,956,621, this number represents the number of seconds since 1 January 1970 (UTC).
2024-01-11T04:48:35.000Z → 1,704,948,515, this number represents the number of seconds since 1 January 1970 (UTC).
So, if we calculate 1,708,956,621 - 1,704,948,515 = 4,008,106 → 4,008,106 seconds. 4,008,106 / 86,400 → 46.4 days
No comments:
Post a Comment