Skip to content

DateTime#

DateTime.day#

Description: The day of the month (1-31)

Syntax: DateTime.day

Returns: Number

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.day //=> 30

DateTime.diffTo()#

Description: Returns the difference between two DateTimes, in the given unit(s)

Syntax: DateTime.diffTo(otherDateTime, unit)

Returns: Number

Source: Custom n8n functionality

Parameters:

  • otherDateTime (String|DateTime) - The moment to subtract the base DateTime from. Can be an ISO date string or a Luxon DateTime.
  • unit (String|Array) - optional - The unit, or array of units, to return the result in. Possible values: years, months, weeks, days, hours, minutes, seconds, milliseconds.

Examples:

1
2
// dt1 = "2024-03-30T18:49:07.234".toDateTime()
dt1.diffTo('2025-01-01', 'days') //=> 276.21
1
2
3
// dt1 = "2024-03-30T18:49:07.234".toDateTime()
// dt2 = "2025-01-01T00:00:00.000".toDateTime()
dt1.diffTo(dt2, ['months', 'days']) //=> {'months':, 'days':}
1
Note: should support both day and days, etc.

DateTime.diffToNow()#

Description: Returns the difference between the current moment and the DateTime, in the given unit(s). For a textual representation, use toRelative() instead.

Syntax: DateTime.diffToNow(unit)

Returns: Number

Source: Custom n8n functionality

Parameters:

  • unit (String|Array) - optional - The unit, or array of units, to return the result in. Possible values: years, months, weeks, days, hours, minutes, seconds, milliseconds.

Examples:

1
2
// dt = "2023-03-30T18:49:07.234".toDateTime()
dt.diffToNow('days') //=> 371.9
1
2
// dt = "2023-03-30T18:49:07.234".toDateTime()
dt.diffToNow(['months', 'days']) //=> {"months":12, "days":5.9}
1
Note: should support both day and days, etc.

DateTime.endOf()#

Description: Rounds the DateTime up to the end of one of its units, e.g. the end of the month

Syntax: DateTime.endOf(unit, opts)

Returns: DateTime

Type: Luxon

Parameters:

  • unit (String) - The unit to round to the end of. Can be year, quarter, month, week, day, hour, minute, second, or millisecond.
  • opts (Object) - optional - Object with options that affect the output. Possible properties: useLocaleWeeks (boolean): Whether to use the locale when calculating the start of the week. Defaults to false.

Examples:

1
2
// dt = "2024-03-20T18:49".toDateTime()
dt.endOf('month') //=> 2024-03-31T23:59

DateTime.equals()#

Description: Returns true if the two DateTimes represent exactly the same moment and are in the same time zone. For a less strict comparison, use hasSame().

Syntax: DateTime.equals(other)

Returns: Boolean

Type: Luxon

Parameters:

  • other (DateTime) - The other DateTime to compare

Examples:

1
2
3
// dt1 = "2024-03-20T18:49+01:00".toDateTime()
// dt2 = "2024-03-20T19:49+02:00".toDateTime()
dt1.equals(dt2) //=> false

DateTime.extract()#

Description: Extracts a part of the date or time, e.g. the month, as a number. To extract textual names instead, see format().

Syntax: DateTime.extract(unit?)

Returns: Number

Source: Custom n8n functionality

Parameters:

  • unit (String) - optional - The part of the date or time to return. One of: year, month, week, day, hour, minute, second

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.extract('month') //=> 3
1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.extract('hour') //=> 18

DateTime.format()#

Description: Converts the DateTime to a string, using the format specified. Formatting guide. For common formats, toLocaleString() may be easier.

Syntax: DateTime.format(fmt)

Returns: String

Source: Custom n8n functionality

Parameters:

  • fmt (String) - The format of the string to return

Examples:

1
2
// dt = "2024-04-30T18:49".toDateTime()
dt.format('dd/LL/yyyy') //=> '30/04/2024'
1
2
3
4
// dt = "2024-04-30T18:49".toDateTime()
dt.format('dd LLL yy') //=> '30 Apr 24'
dt.setLocale('fr').format('dd LLL yyyy') //=> '30 avr. 2024'
dt.format("HH 'hours and' mm 'minutes'") //=> '18 hours and 49 minutes'

DateTime.hasSame()#

Description: Returns true if the two DateTimes are the same, down to the unit specified. Time zones are ignored (only local times are compared), so use toUTC() first if needed.

Syntax: DateTime.hasSame(otherDateTime, unit)

Returns: Boolean

Type: Luxon

Parameters:

  • otherDateTime (DateTime) - The other DateTime to compare
  • unit (String) - The unit of time to check sameness down to. One of year, quarter, month, week, day, hour, minute, second, or millisecond.

Examples:

1
2
3
// dt1 = "2024-03-20".toDateTime()
// dt2 = "2024-03-18".toDateTime()
dt1.hasSame(dt2, 'month') //=> true
1
2
3
// dt1 = "1982-03-20".toDateTime()
// dt2 = "2024-03-18".toDateTime()
dt1.hasSame(dt2, 'month') //=> false

DateTime.hour#

Description: The hour of the day (0-23)

Syntax: DateTime.hour

Returns: Number

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.hour //=> 18

DateTime.isBetween()#

Description: Returns true if the DateTime lies between the two moments specified

Syntax: DateTime.isBetween(date1, date2)

Returns: Boolean

Source: Custom n8n functionality

Parameters:

  • date1 (String|DateTime) - The moment that the base DateTime must be after. Can be an ISO date string or a Luxon DateTime.
  • date2 (String|DateTime) - The moment that the base DateTime must be before. Can be an ISO date string or a Luxon DateTime.

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.isBetween('2020-06-01', '2025-06-01') //=> true
1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.isBetween('2020', $now) //=> true

DateTime.isInDST#

Description: Whether the DateTime is in daylight saving time

Syntax: DateTime.isInDST

Returns: Boolean

Type: Luxon

DateTime.locale#

Description: The locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime.

Syntax: DateTime.locale

Returns: String

Type: Luxon

Examples:

1
$now.locale //=> 'en-US'

DateTime.millisecond#

Description: The millisecond of the second (0-999)

Syntax: DateTime.millisecond

Returns: Number

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49:07.234".toDateTime()
dt.millisecond //=> 234

DateTime.minus()#

Description: Subtracts a given period of time from the DateTime

Syntax: DateTime.minus(n, unit?)

Returns: DateTime

Source: Custom n8n functionality

Parameters:

  • n (Number|Object) - The number of units to subtract. Or use a Luxon Duration object to subtract multiple units at once.
  • unit (String) - optional - The units of the number. One of: years, months, weeks, days, hours, minutes, seconds, milliseconds

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.minus(7, 'days') //=> 2024-04-23T18:49
1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.minus(4, 'years') //=> 2020-04-30T18:49

DateTime.minute#

Description: The minute of the hour (0-59)

Syntax: DateTime.minute

Returns: Number

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.minute //=> 49

DateTime.month#

Description: The month (1-12)

Syntax: DateTime.month

Returns: Number

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.month //=> 3

DateTime.monthLong#

Description: The textual long month name, e.g. 'October'. Defaults to the system's locale if no locale has been specified.

Syntax: DateTime.monthLong

Returns: String

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.monthLong //=> 'March'
1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.setLocale('de-DE').monthLong //=> 'März'

DateTime.monthShort#

Description: The textual abbreviated month name, e.g. 'Oct'. Defaults to the system's locale if no locale has been specified.

Syntax: DateTime.monthShort

Returns: String

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.monthShort //=> 'Mar'
1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.setLocale('de-DE').monthShort //=> 'Mär'

DateTime.plus()#

Description: Adds a given period of time to the DateTime

Syntax: DateTime.plus(n, unit?)

Returns: DateTime

Source: Custom n8n functionality

Parameters:

  • n (Number|Object) - The number of units to add. Or use a Luxon Duration object to add multiple units at once.
  • unit (String) - optional - The units of the number. One of: years, months, weeks, days, hours, minutes, seconds, milliseconds

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.plus(7, 'days') //=> 2024-05-07T18:49
1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.plus(4, 'years') //=> 2028-04-30T18:49

DateTime.quarter#

Description: The quarter of the year (1-4)

Syntax: DateTime.quarter

Returns: Number

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.quarter //=> 1

DateTime.second#

Description: The second of the minute (0-59)

Syntax: DateTime.second

Returns: Number

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49:07.234".toDateTime()
dt.second //=> 7

DateTime.set()#

Description: Assigns new values to specified units of the DateTime. To round a DateTime, see also startOf() and endOf().

Syntax: DateTime.set(values)

Returns: DateTime

Type: Luxon

Parameters:

  • values (Object) - An object containing the units to set and corresponding values to assign. Possible keys are year, month, day, hour, minute, second and millsecond.

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.set({year:1982, month:10}) //=> 1982-10-20T18:49

DateTime.setLocale()#

Description: Sets the locale, which determines the language and formatting for the DateTime. Useful when generating a textual representation of the DateTime, e.g. with format() or toLocaleString().

Syntax: DateTime.setLocale(locale)

Returns: DateTime

Type: Luxon

Parameters:

  • locale (String) - The locale to assign, e.g. ‘en-GB’ for British English or ‘pt-BR’ for Brazilian Portuguese. List (unofficial)

Examples:

1
$now.setLocale('de-DE').toLocaleString({'dateStyle':'long'}) //=> 5. Oktober 2024
1
$now.setLocale('fr-FR').toLocaleString({'dateStyle':'long'}) //=> 5 octobre 2024

DateTime.setZone()#

Description: Converts the DateTime to the given time zone. The DateTime still represents the same moment unless specified in the options. See also toLocal() and toUTC().

Syntax: DateTime.setZone(zone, opts)

Returns: DateTime

Type: Luxon

Parameters:

  • zone (String) - optional - A zone identifier, either in the format ‘America/New_York’, 'UTC+3', or the strings 'local' or 'utc'
  • opts (Object) - optional - Options that affect the output. Possible properties: keepCalendarTime (boolean): Whether to keep the time the same and only change the offset. Defaults to false.

Examples:

1
2
// dt = "2024-01-01T00:00:00.000+02:00".toDateTime()
dt.setZone('America/Buenos_aires') //=> 2023-12-31T19:00:00.000-03:00
1
2
// dt = "2024-01-01T00:00:00.000+02:00".toDateTime()
dt.setZone('UTC+7') //=> 2024-01-01T05:00:00.000+07:00

DateTime.startOf()#

Description: Rounds the DateTime down to the beginning of one of its units, e.g. the start of the month

Syntax: DateTime.startOf(unit, opts)

Returns: DateTime

Type: Luxon

Parameters:

  • unit (String) - The unit to round to the beginning of. One of year, quarter, month, week, day, hour, minute, second, or millisecond.
  • opts (Object) - optional - Object with options that affect the output. Possible properties: useLocaleWeeks (boolean): Whether to use the locale when calculating the start of the week. Defaults to false.

Examples:

1
2
// dt = "2024-03-20T18:49".toDateTime()
dt.startOf('month') //=> 2024-03-01T00:00

DateTime.toISO()#

Description: Returns an ISO 8601-compliant string representation of the DateTime

Syntax: DateTime.toISO(opts)

Returns: String

Type: Luxon

Parameters:

  • opts (Object) - optional - Configuration options. See Luxon docs for more info.

Examples:

1
$now.toISO() //=> 2024-04-05T18:44:55.525+02:00

DateTime.toLocal()#

Description: Converts a DateTime to the workflow’s local time zone. The DateTime still represents the same moment unless specified in the parameters. The workflow’s time zone can be set in the workflow settings.

Syntax: DateTime.toLocal()

Returns: DateTime

Type: Luxon

Examples:

1
2
// dt = "2024-01-01T00:00:00.000Z".toDateTime()
dt.toLocal() //=> 2024-01-01T01:00:00.000+01:00, if time zone is Europe/Berlin

DateTime.toLocaleString()#

Description: Returns a localised string representing the DateTime, i.e. in the language and format corresponding to its locale. Defaults to the system's locale if none specified.

Syntax: DateTime.toLocaleString(formatOpts)

Returns: String

Type: Luxon

Parameters:

  • formatOpts (Object) - optional - Configuration options for the rendering. See Intl.DateTimeFormat for a full list. Defaults to rendering a short date.

Examples:

1
2
3
$now.toLocaleString() //=> '4/30/2024'
$now.toLocaleString({'dateStyle':'medium', 'timeStyle':'short'}) //=> 'Apr 30, 2024, 10:00 PM'
// (if in US English locale)
1
$now.setLocale('de-DE').toLocaleString() //=> '30.4.2024'
1
2
3
4
5
$now.toLocaleString({'dateStyle':'short'}) //=> '4/30/2024'
$now.toLocaleString({'dateStyle':'medium'}) //=> 'Apr 30, 2024'
$now.toLocaleString({'dateStyle':'long'}) //=> 'April 30, 2024'
$now.toLocaleString({'dateStyle':'full'}) //=> 'Tuesday, April 30, 2024'
// (if in US English locale)
1
2
3
4
5
$now.toLocaleString({'year':'numeric', 'month':'numeric', 'day':'numeric'}) //=> '4/30/2024'
$now.toLocaleString({'year':'2-digit', 'month':'2-digit', 'day':'2-digit'}) //=> '04/30/24'
$now.toLocaleString({'month':'short', 'weekday':'short', 'day':'numeric'}) //=> 'Tue, Apr 30'
$now.toLocaleString({'month':'long', 'weekday':'long', 'day':'numeric'}) //=> 'Tuesday, April 30'
// (if in US English locale)
1
2
3
4
5
$now.toLocaleString({'timeStyle':'short'}) //=> '10:00 PM'
$now.toLocaleString({'timeStyle':'medium'}) //=> '10:00:58 PM'
$now.toLocaleString({'timeStyle':'long'}) //=> '10:00:58 PM GMT+2'
$now.toLocaleString({'timeStyle':'full'}) //=> '10:00:58 PM Central European Summer Time'
// (if in US English locale)
1
2
3
$now.toLocaleString({'hour':'numeric', 'minute':'numeric', hourCycle:'h24'}) //=> '22:00'
$now.toLocaleString({'hour':'2-digit', 'minute':'2-digit', hourCycle:'h12'}) //=> '10:00 PM'
// (if in US English locale)

DateTime.toMillis()#

Description: Returns a Unix timestamp in milliseconds (the number elapsed since 1st Jan 1970)

Syntax: DateTime.toMillis()

Returns: Number

Type: Luxon

Examples:

1
$now.toMillis() //=> 1712334324677

DateTime.toRelative()#

Description: Returns a textual representation of the time relative to now, e.g. ‘in two days’. Rounds down by default.

Syntax: DateTime.toRelative(options)

Returns: String

Type: Luxon

Parameters:

  • options (Object) - optional - Options that affect the output. Possible properties: unit = the unit to default to (years, months, days, etc.). locale = the language and formatting to use (e.g. de, fr)

Examples:

1
$now.plus(1, 'day').toRelative() //=> "in 1 day"
1
$now.plus(1, 'day').toRelative({unit:'hours'}) //=> "in 24 hours"
1
$now.plus(1, 'day').toRelative({locale:'es'}) //=> "dentro de 1 día"

DateTime.toSeconds()#

Description: Returns a Unix timestamp in seconds (the number elapsed since 1st Jan 1970)

Syntax: DateTime.toSeconds()

Returns: Number

Type: Luxon

Examples:

1
$now.toSeconds() //=> 1712334442.372

DateTime.toString()#

Description: Returns a string representation of the DateTime. Similar to toISO(). For more formatting options, see format() or toLocaleString().

Syntax: DateTime.toString()

Returns: string

Type: Luxon

Examples:

1
$now.toString() //=> 2024-04-05T18:44:55.525+02:00

DateTime.toUTC()#

Description: Converts a DateTime to the UTC time zone. The DateTime still represents the same moment unless specified in the parameters. Use setZone() to convert to other zones.

Syntax: DateTime.toUTC(offset, opts)

Returns: DateTime

Type: Luxon

Parameters:

  • offset (Number) - optional - An offset from UTC in minutes
  • opts (Object) - optional - Object with options that affect the output. Possible properties: keepCalendarTime (boolean): Whether to keep the time the same and only change the offset. Defaults to false.

Examples:

1
2
// dt = "2024-01-01T00:00:00.000+02:00".toDateTime()
dt.toUTC() //=> 2023-12-31T22:00:00.000Z

DateTime.weekday#

Description: The day of the week. 1 is Monday and 7 is Sunday.

Syntax: DateTime.weekday

Returns: Number

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.weekday //=> 6

DateTime.weekdayLong#

Description: The textual long weekday name, e.g. 'Wednesday'. Defaults to the system's locale if no locale has been specified.

Syntax: DateTime.weekdayLong

Returns: String

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.weekdayLong //=> 'Saturday'
1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.setLocale('de-DE').weekdayLong //=> 'Samstag'

DateTime.weekdayShort#

Description: The textual abbreviated weekday name, e.g. 'Wed'. Defaults to the system's locale if no locale has been specified.

Syntax: DateTime.weekdayShort

Returns: String

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.weekdayShort //=> 'Sat'
1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.setLocale('fr-FR').weekdayShort //=> 'sam.'

DateTime.weekNumber#

Description: The week number of the year (1-52ish)

Syntax: DateTime.weekNumber

Returns: Number

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.weekNumber //=> 13

DateTime.year#

Description: The year

Syntax: DateTime.year

Returns: Number

Type: Luxon

Examples:

1
2
// dt = "2024-03-30T18:49".toDateTime()
dt.year //=> 2024

DateTime.zone#

Description: The time zone associated with the DateTime

Syntax: DateTime.zone

Returns: Object

Type: Luxon

Examples:

1
$now.zone //=> {"zoneName": "Europe/Berlin", "valid": true}
This page was