Articles on: Connectors

Function Expressions - Date and Time

Overview


A DateTime function performs an action or calculation on a date and time value. Use a DateTime function to add or subtract intervals, find the current date, find the first or last day of the month, extract a component of a DateTime value, or convert a value to a different format.

VARIABLES



Timestamp


Unix timestamp. Number of seconds since midnight January 1, 1970

Now Date


Current Date and time.

FUNCTIONS



timeDiff


Returns the difference between 2 dates in millisecond. Startdate and enddate should have the same format. eg: timeDiff(2021-06-04T22:27:01, 2021-06-04T22:27:04, %Y-%m-%DT%H:%M:%S.%f)
Syntax: timeDiff (Startdate, enddate, format)


toTimestamp


Convert date to Timestamp. eg: toTimestamp(2021-06-04T22:27:01, %Y-%m-%DT%H:%M:%S)
Syntax: toTimestamp (date, format)


toDate


Convert timestamp to date e.g: toDate (1622809621)
Syntax: toDate(date)



addSeconds


Returns a new date as a result of adding a given number of seconds to a date. To subtract seconds, enter a negative number.
Syntax: addSeconds(date, number)


addMinutes


Returns a new date as a result of adding a given number of minutes to a date. To subtract minutes, enter a negative number.
Syntax: addMinutes(date, number)


addHours


Returns a new date as a result of adding a given number of hours to a date. To subtract hours, enter a negative number.
Syntax: addHours (date, number)


addDays


Returns a new date as a result of adding a given number of days to a date. To subtract days, enter a negative number.
Syntax: addDays (date, number)


addMonths


Returns a new date as a result of adding a given number of months to a date. To subtract months, enter a negative number.
Syntax: addMonths (date, number)


addYears


Returns a new date as a result of adding a given number of years to a date. To subtract years, enter a negative number.
Syntax: addYears(date, number)


setSecond


Returns a new date with the seconds specified in parameters. Accepts numbers from 0 to 59. If a number is given outside of this range, it will return the date with the seconds from the previous or subsequent minute (s) accordingly.
Syntax: setSecond (date, number)


setMinute


Returns a new date with the minutes specified in parameters. Accepts numbers from 0 to 59. If a number is given outside of this range, it will return the date with the seconds from the previous or subsequent hour (s) accordingly.
Syntax: setMinute (date, number)


setHour


Returns a new date with the hours specified in parameters. Accepts numbers from 0 to 23. If a number is given outside of this range, it will return the date with the seconds from the previous or subsequent day (s) accordingly.
Syntax: setHour (date, number)


setDay


Returns a new date with the day of the month specified in parameters. Accepts numbers from 1 to 31. If a number is given outside of this range, it will return the date with the day from the previous or subsequent month (s) accordingly.
Syntax: setDay (date, number)


setMonth


Returns a new date with the month specified in parameters. Accepts numbers from 1 to 12. If a number is given outside of this range, it will return the date with the month from the previous or subsequent year (s) accordingly.
Syntax: setMonth (date, number/name of the month in English)


setYear


Returns a new date with the year specified in parameters.
Syntax: setYear( date, number)


formatDate


returns date based on format codes. For example, format DD.MM.YYYY HH:mm
formatDate(<date iso>, <format code>)


<date iso>: date based on IOS format. eg: "%Y-%m-%dT%H:%M:%S" (2021-04-12T00:00:00). Also array of date strings can be sent
<format>: out format. https://www.programiz.com/python-programming/datetime/strptime

formatDate( "20210412", "%B")
formatDate( ["20210412", "20210413"], "%A")
output
--------
December
["Wednesday","Thursday"]



parseDate


parses a string with a date and returns the date
parseDate(<stringDate>)

<stringDate>: date to parse. Also array of date strings can be sent
<stringDate> is array then the output format will be always "iso" (2020-04-13T00:00:00.000Z)

parseDate( "20210412")
parseDate( ["20210412", "20210413"])

output:
----------
2021-04-12T00:00:00
["2020-04-12T00:00:00.000Z","2020-04-13T00:00:00.000Z"]



analyticsDate


convert analytics friendly date to date range .

Syntax: analyticsDate(<friendlydate>). e.g: today, yesterday, thismonth...


date
all
today, thisweek, thismonth, thisquarter, thisyear, weektodate, monthtodate, quartertodate, yeartodate
yesterday, lastweek, lastmonth, lastquarter, lastyear


Examples

analyticsDate(lastweek)
output
---------
['2021-04-19T00:00:00', '2021-04-25T23:59:59']



analyticsDatecompare


convert analytics friendly compare date, to date range .
Syntax: analyticsDatecompare(<compare friendly date>, <friendly date>)


date_compare
previous
1weekago, 2weeksago, 3weeksago
1monthago, 2monthsago, 3monthsago, 4monthsago, 5monthsago, 6monthsago, 7monthsago, 8monthsago, 9monthsago, 10monthsago, 11monthsago
1yearago, 2yearsago


Example

analyticsDatecompare(previous, lastweek)
output----------['2021-04-12T00:00:00', '2021-04-28T23:59:59']

Updated on: 20/07/2022

Was this article helpful?

Share your feedback

Cancel

Thank you!