Explore more
Functions

Date and time functions

38min

Use date and time functions to convert and transform date and time data. For example, you can change the date format, convert time based on timezones, convert text to date or time data, and more. Below is a list of supported date and time functions with descriptions and details for each.

formatDate (date; format; [timezone])

When to use it: You have a date value that you wish to convert (format) to a text value (textual human-readable representation) like 12-10-2019 20:30 or Aug 18, 2019 10:00 AM

Parameters

The second column indicates the expected type. If different type is provided, type coercion is applied.

Parameter

Expected type

Description

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. The timezone used for the conversion.

See List of tz database time zones, column "TZ database name" for the list of recognized timezones.

If omitted, uses the organization's timezone. You can edit your time zone.

Return value and type

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

Example

The Organization's and Web's timezone were both set to Europe/Prague in the following examples.

Function

Result

formatDate(1. Date created; MM/DD/YYYY )

10/01/2018

formatDate(1. Date created; YYYY-MM-DD hh:mm A )

2018-10-01 09:32 AM

formatDate(1. Date created; DD.MM.YYYY HH:mm ; UTC )

01.10.2018 07:32

formatDate(now; MM/DD/YYYY HH:mm )

19/03/2019 15:30

parseDate (text; format; [timezone])

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

Parameters

The second column indicates the expected type. If different type is provided, Type Coercion is applied.

Parameter

Expected type

Description

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. The timezone used for the conversion.

See List of tz database time zones, column "TZ database name" for the list of recognized timezones.

If omitted, uses the organization's timezone. You can edit your time zone.

Example: Europe/PragueUTC

Return value and type

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

Examples

Please note that in the following examples the returned date value is expressed according to ISO 8601, but the actual resulting value is of type date.

Text

Text

Text

Text


addDays (date; number)

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

Text

Text


addHours (date; number)

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

Text

Text


addMinutes (date; number)

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

Text

Text


addMonths (date; number)

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

Text

Text


addSeconds (date; number)

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

Text

Text


addYears (date; years)

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

Text

Text


setSecond (date; number)

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.

Text

Text


setMinute (date; number)

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 minutes from the previous or subsequent hour(s), accordingly.

Text

Text


setHour (date; number)

Returns a new date with the hour 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 hour from the previous or subsequent day(s), accordingly.

Text

Text


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

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), accordingly.

Text

Text

Text


setDate (date; number)

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 the range, it will return the day from the previous or subsequent month(s), accordingly.

Text

Text


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

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 month in the previous or subsequent year(s), accordingly.

Text

Text

Text


setYear (date; number)

Returns a new date with the year specified in parameters.

Text


Examples

Calculate n-th day of the week in a month

If you need to calculate a date corresponding to the n-th day of week in a month (e.g. 1st Tuesday, 3rd Friday, etc.), you can use the following formula:

Text


The formula contains the following items:

Value

Description

1.n

n-th day:

  • 1 for 1st Tuesday
  • 2 for 2nd Tuesday
  • 3 for 3rd Tuesday
  • etc.

2.dow

Day of the week:

  • 1 for Monday
  • 2 for Tuesday
  • 3 for Wednesday
  • 4 for Thursday
  • 5 for Friday
  • 6 for Saturday
  • 7 for Sunday

1.date

The date determines the month. To calculate n-th day of week in current month use the now variable

If you want to calculate only one specific case, e.g. 2nd Wednesday, you may replace the items 1.n and 2.dow in the formula with the corresponding numbers. For 2nd Wednesday in the current month you would use the following values:

  • 1.n = 2
  • 1.dow = 3
  • 1.date = now
  • setDate(now;1) returns first of current month
  • formatDate(....;E) returns day of week (1, 2, ... 6)
  • see the original source for the rest

Calculate days between dates

Calculate days between d

Text


The values of D1 and D2 above have to be of type date. If they are of type string (e.g. "20.10.2018"), use the parseDate() function to convert them to type date.

The round() function is used for cases when one of the dates falls within the daylight savings time period and the other does not. In these cases, the difference in hours is by one hour less/more and dividing it by 24 gives a non-integer results.

Calculate the last day/millisecond of a month

When specifying a date range (e.g. in a search module) spanning the whole previous month as a closed interval (the interval that includes both its limit points), it is necessary to calculate the last day of the month.

2019-09-01 ≤ D ≤ 2019-09-30

Text


In some cases, it is necessary to calculate not only the last day of month, but its last millisecond:

2019-09-01T00:00:00.000Z ≤ D ≤ 2019-09-30T23:59:59.999Z

Text


If the result should respect your timezone settings, simply omit the UTC argument:

Text


However, it is preferable to use a half-open interval instead (the interval that excludes one of its limit points), specifying the first day of the following month instead and replacing the less or equal than operator with less than:

2019-09-01 ≤ D < 2019-10-01

2019-09-01T00:00:00.000Z ≤ D < 2019-10-01T00:00:00.000Z

Transform seconds into hours, minutes and second

Text


Values of second should be number type. This function is suited only if the second value is less than 86400 ( less than a day ).