For the complete documentation index, see llms.txt. This page is also available as Markdown.

DateTime module

The DateTime module contains functions for working with datetime values. Most of the functions are declared as self functions: by opening the DateTime module in a script step, you can use dot notation to call the functions on datetime values.

// Example 1: access the datetime module without opening it
return DateTime.addYears(now(), 1);
// Example 2: open the DateTime module and use it.
open DateTime;
return now().addYears(1);
Advanced: Time zones

All datetime values contain a Time Zone Offset. This ensures that values created on different devices "mean" the same absolute time.

Creating and Parsing datetime values

createDate

Signature: createDate(year: number, month: number, day: number) -> datetime

Returns a datetime value with the given year, month and day. The time portion of the datetime will be set to 00:00:00. The offset will be set to the local time zone.

createDateAndTime

Signature: createDateAndTime(year: number, month: number, day: number, hour: number, minute: number, second: number) -> datetime

Returns a datetime value with the given year, month, day, hour (in 24-hour time), minute and second.

the offset will be set to the local time zone.

isValidDate

Signature: isValidDate(input: any) -> boolean

Returns true if the input value can be converted to a valid date. Arguments that returns true can be used with the Date function to create a datetime value.

Modifying datetime values

addSeconds

Signature: addSeconds(self input: datetime, seconds: number) -> datetime

Returns a new date obtained by adding the specified number of seconds to the input date. You can pass a negative number to subtract seconds.

addMinutes

Signature: addMinutes(self input: datetime, minutes: number) -> datetime

Returns a new date obtained by adding the specified number of minutes to the input date. You can pass a negative number to subtract minutes.

addHours

Signature: addHours(self input: datetime, hours: number) -> datetime

Returns a new date obtained by adding the specified number of hours to the input date. You can pass a negative number to subtract hours.

addDays

Signature: addDays(self input: datetime, days: number) -> datetime

Returns a new date obtained by adding the specified number of days to the input date. You can pass a negative number to subtract days.

addMonths

Signature: addMonths(self input: datetime, months: number) -> datetime

Returns a new date obtained by adding the specified number of months to the input date. You can pass a negative number to subtract months.

addYears

Signature: addYears(self input: datetime, months: number) -> datetime

Returns a new date obtained by adding the specified number of years to the input date. You can pass a negative number to subtract years.

setTime

Signature: setTime(date: datetime, hour: number, minute: number, second: number) -> datetime

Returns a new date obtained from the given date with the hours, minutes and second set by the provided arguments.

toUtc

Signature: toUtc(self date: datetime) -> datetime

`Returns the given date converted to UTC.

toLocal

Signature: toLocal(self date: datetime) -> datetime

Returns the given date converted to local time.

Retrieving data from datetime values

getSecond

Signature: getSecond(self input: datetime) -> number

Returns the second component of the datetime value.

getMinute

Signature: getMinute(self input: datetime) -> number

Returns the minute component of the datetime value.

getHour

Signature: getHour(self input: datetime) -> number

Returns the hour component of the datetime value, in 24-hour time.

getDayOfMonth

Signature: getDayOfMonth(self input: datetime) -> number

Returns the day component of the datetime value.

getDayOfWeek

Signature: getDayOfWeek(self input: datetime) -> text

Returns the day of week for the given datetime value. Return values are English-laguage text values "monday", "tuesday" etc.

getMonth

Signature: getMonth(self input: datetime) -> number

Returns the month component of the datetime value.

getYear

Signature: getYear(self input: datetime) -> number

Returns the year component of the datetime value.

getTimeOffset

Signature: getTimeZoneOffset(self input: datetime) -> number

Returns the offset from UTC of the datetime value.

Comparing dates

differenceInDays

Signature: differenceInDays(fromDate: datetime, toDate: datetime) -> number

Returns the difference in days between two dates.

differenceInSeconds

Signature: differenceInSeconds(fromDate: datetime, toDate: datetime) -> number

Returns the difference in seconds between two dates.

HHMM text

createHHMMText

Signature: createHHMMText(input: datetime) -> text

Returns a text representation of datetime value hours and minutes

getMinuteFromHHMMText

Signature: getMinuteFromHHMMText(input: text) -> number

Returns the number of minutes from a HHMM formatted text.

getHourFromHHMMText

Signature: getHourFromHHMMText(input: text) -> number

Returns the number of hours from a HHMM formatted text.

Last updated

Was this helpful?