Date and Time Functions

Rita Pang
Rita Pang
  • Updated

The below are a list of functions to format date and time within your Alaya Connector scenarios.

formatDate (date; format; [timezone])

When users have a date value whose format they wish to convert to a text value like 12-10-2019 20:30 or Aug 18, 2019 10:00 AM, the following parameters can be used. 

Parameters

The second column of these parameters indicates the expected type. Type Coercion will be applied if a different type is provided.

  Type Explanation
date Date Date value to be converted to a Text value.
format Text Format specified using Tokens for date/time formatting.
Example: DD.MM.YYYY HH:mm
timezone Text Optional. Please note that not all timezones are recognized. Check with your account manager for more details. 
If omitted, the timezone specified in the user's profile settings will be applied. You can find the settings under Time zone options> Scenarios> the organization the scenario belongs to
Examples: Europe/PragueUTC

Return value and type

Text representation of the given Date value according to the specified format and timezone. Type is Text.

parseDate (text; format; [timezone])

When users have a text value representing a date (e.g. 12-10-2019 20:30 or Aug 18, 2019 10:00 AM) and they wish to convert (parse) it to a date value (binary machine readable representation) instead, they can use this function.

Parameters

The second column of these parameters indicates the expected type. Type Coercion will be applied if a different type is provided.

  Type Explanation
text Text Text value to be converted to a Date value.
format Text Format specified using Tokens for date/time formatting.
Example: DD.MM.YYYY HH:mm
timezone Text Optional. Please note that not all timezones are recognized. Check with your account manager for more details. 
If omitted, the timezone specified in the user's profile settings will be applied. You can find the settings under Time zone options> Scenarios> the organization the scenario belongs to
Examples: Europe/PragueUTC
 

Return value and type

Date representation of the given Date value according to the specified format and timezone. Type is date.

addDays (date; number)

This function returns a new date as a result of adding a given number of days to a date. To subtract days, enter a negative number.

addDays(2016-12-08T15:55:57.536Z;2)
= 2016-12-10T15:55:57.536Z
addDays(2016-12-08T15:55:57.536Z;-2)
= 2016-12-6T15:55:57.536Z

addHours (date; number)

This function returns a new date as a result of adding a given number of hours to a date. To subtract hours, enter a negative number.

addHours(2016-12-08T15:55:57.536Z;2)
= 2016-12-08T17:55:57.536Z
addHours(2016-12-08T15:55:57.536Z;-2)
= 2016-12-08T13:55:57.536Z

addMinutes (date; number)

This function returns a new date as a result of adding a given number of minutes to a date. To subtract minutes, enter a negative number.

addMinutes(2016-12-08T15:55:57.536Z;2)
= 2016-12-08T15:57:57.536Z
addMinutes(2016-12-08T15:55:57.536Z;-2)
= 2016-12-08T15:53:57.536Z

addMonths (date; number)

This function returns a new date as a result of adding a given number of months to a date. To subtract months, enter a negative number.

addMonths(2016-08-08T15:55:57.536Z;2)
= 2016-10-08T15:55:57.536Z
addMonths(2016-08-08T15:55:57.536Z;-2)
= 2016-06-08T15:55:57.536Z

addSeconds (date; number)

This function returns a new date as a result of adding a given number of seconds to a date. To subtract seconds, enter a negative number.

addSeconds(2016-12-08T15:55:57.536Z;2)
= 2016-12-08T15:55:59.536Z
addSeconds(2016-12-08T15:55:57.536Z;-2)
= 2016-12-08T15:55:55.536Z

addYears (date;years)

This function returns a new date as a result of adding a given number of years to a date. To subtract years, enter a negative number.

addYears(2016-08-08T15:55:57.536Z;2)
= 2018-08-08T15:55:57.536Z
addYears(2016-08-08T15:55:57.536Z;-2)
= 2014-08-08T15:55:57.536Z

setSecond (date; number)

This function returns a new date with the seconds specified in parameters and 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).

setSecond(2015-10-07T11:36:39.138Z;10)
= 2015-10-07T11:36:10.138Z
setSecond(2015-10-07T11:36:39.138Z;61)
= 2015-10-07T11:37:01.138Z

setMinute (date; number)

This function returns a new date with the minutes specified in parameters and acccepts numbers from 0 to 59. If a number is given outside of the range, it will return the date with the minutes from the previous or subsequent hour(s).

setMinute(2015-10-07T11:36:39.138Z;10)
= 2015-10-07T11:10:39.138Z
setMinute(2015-10-07T11:36:39.138Z;61)
= 2015-10-07T12:01:39.138Z

setHour (date; number)

This function returns a new date with the hour specified in parameters and accepts numbers from 0 to 23. If a number is given outside of the range, it will return the date with the hour from the previous or subsequent day(s).

setHour(2015-08-07T11:36:39.138Z;6)
= 2015-08-07T06:36:39.138Z
setHour(2015-08-07T11:36:39.138Z;-6)
= 2015-08-06T18:36:39.138Z

setDay (date; number/name of the day in english)

This function returns a new date with the day specified in parameters. It can be used to set the day of the week, with Sunday as 1 and Saturday as 7. If the given value is from 1 to 7, the resulting date will be within the current (Sunday-to-Saturday) week. If a number is given outside of the range, it will return the day from the previous or subsequent week(s).

setDay(2018-06-27T11:36:39.138Z;monday)
= 2018-06-25T11:36:39.138Z
setDay(2018-06-27T11:36:39.138Z;1)
= 2018-06-24T11:36:39.138Z
setDay(2018-06-27T11:36:39.138Z;7)
= 2018-06-30T11:36:39.138Z

setDate (date; number)

This function returns a new date with the day of the month specified in parameters and accepts numbers from 1 to 31. If a number is given outside of the range, it will return the day from the previous or subsequent month(s).

setDate(2015-08-07T11:36:39.138Z;5)
= 2015-08-05T11:36:39.138Z
setDate(2015-08-07T11:36:39.138Z;32)
= 2015-09-01T11:36:39.138Z

setMonth (date; number/name of the month in English)

This function returns a new date with the month specified in parameters and accepts numbers from 1 to 12. If a number is given outside of this range, it will return the month in the previous or subsequent year(s).

setMonth(2015-08-07T11:36:39.138Z;5)
= 2015-05-07T11:36:39.138Z
setMonth(2015-08-07T11:36:39.138Z;17)
= 2016-05-07T11:36:39.138Z
setMonth(2015-08-07T11:36:39.138Z;january)
= 2015-01-07T12:36:39.138Z

setYear (date; number)

This function returns a new date with the year specified in parameters.

setYear(2015-08-07T11:36:39.138Z;2017)
= 2017-08-07T11:36:39.138Z

More instructions will soon be available pertaining to the calculation of dates and time within Alaya Connector.

Was this article helpful?

0 out of 3 found this helpful

Comments

0 comments

Article is closed for comments.