Datetime
DateTime.day
DateTime.dayDescription: The day of the month (1-31)
Syntax: DateTime.day
Returns: Number
Type: Luxon
Examples:
// dt = "2024-03-30T18:49".toDateTime()
dt.day //=> 30DateTime.diffTo()
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:
DateTime.diffToNow()
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:
DateTime.endOf()
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 beyear,quarter,month,week,day,hour,minute,second, ormillisecond.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:
DateTime.equals()
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:
DateTime.extract()
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:
DateTime.format()
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:
Not available in the Code node
format() is a custom n8n extension added to Luxon DateTime objects in the expressions editor. It doesn't exist in the Code node, because Code node scripts run against plain, unmodified Luxon. Calling it there throws ... .format is not a function.
Use Luxon's native toFormat() instead:
This applies to any method on this page marked Source: Custom n8n functionality: it's available in expressions (e.g. the Set node) but may not be available in the Code node. See Built-in methods and variables for more on this distinction.
DateTime.hasSame()
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 compareunit(String) - The unit of time to check sameness down to. One ofyear,quarter,month,week,day,hour,minute,second, ormillisecond.
Examples:
DateTime.hour
DateTime.hourDescription: The hour of the day (0-23)
Syntax: DateTime.hour
Returns: Number
Type: Luxon
Examples:
DateTime.isBetween()
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:
DateTime.isInDST
DateTime.isInDSTDescription: Whether the DateTime is in daylight saving time
Syntax: DateTime.isInDST
Returns: Boolean
Type: Luxon
DateTime.locale
DateTime.localeDescription: The locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime.
Syntax: DateTime.locale
Returns: String
Type: Luxon
Examples:
DateTime.millisecond
DateTime.millisecondDescription: The millisecond of the second (0-999)
Syntax: DateTime.millisecond
Returns: Number
Type: Luxon
Examples:
DateTime.minus()
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 <a href=”https://moment.github.io/luxon/api-docs/index.html#duration”>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:
Code node: Luxon's native DateTime.prototype.minus() also exists in the Code node, but only accepts a single Duration-like object (e.g. dt.minus({ days: 7 })), not this page's n8n-only (n, unit) shorthand. Passing dt.minus(7, 'days') in the Code node will not raise an error but will not subtract 7 days either — double-check the result if you use this signature there.
DateTime.minute
DateTime.minuteDescription: The minute of the hour (0-59)
Syntax: DateTime.minute
Returns: Number
Type: Luxon
Examples:
DateTime.month
DateTime.monthDescription: The month (1-12)
Syntax: DateTime.month
Returns: Number
Type: Luxon
Examples:
DateTime.monthLong
DateTime.monthLongDescription: 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:
DateTime.monthShort
DateTime.monthShortDescription: 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:
DateTime.plus()
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 <a href=”https://moment.github.io/luxon/api-docs/index.html#duration”>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:
Code node: Luxon's native DateTime.prototype.plus() also exists in the Code node, but only accepts a single Duration-like object (e.g., dt.plus({ days: 7 })), not this page's n8n-only (n, unit) shorthand. Passing dt.plus(7, 'days') in the Code node will not raise an error but will not add 7 days either. Double-check the result if you use this signature there.
DateTime.quarter
DateTime.quarterDescription: The quarter of the year (1-4)
Syntax: DateTime.quarter
Returns: Number
Type: Luxon
Examples:
DateTime.second
DateTime.secondDescription: The second of the minute (0-59)
Syntax: DateTime.second
Returns: Number
Type: Luxon
Examples:
DateTime.set()
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 areyear,month,day,hour,minute,secondandmillsecond.
Examples:
DateTime.setLocale()
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. <a href=”https://www.localeplanet.com/icu/”>List (unofficial)
Examples:
DateTime.setZone()
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:
DateTime.startOf()
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 ofyear,quarter,month,week,day,hour,minute,second, ormillisecond.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:
DateTime.toISO()
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 <a href=”https://moment.github.io/luxon/api-docs/index.html#datetimetoiso”>Luxon docs for more info.
Examples:
DateTime.toLocal()
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:
DateTime.toLocaleString()
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 <a href=”https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#parameters”>Intl.DateTimeFormat for a full list. Defaults to rendering a short date.
Examples:
DateTime.toMillis()
DateTime.toMillis()Description: Returns a Unix timestamp in milliseconds (the number elapsed since 1st Jan 1970)
Syntax: DateTime.toMillis()
Returns: Number
Type: Luxon
Examples:
DateTime.toRelative()
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:
DateTime.toSeconds()
DateTime.toSeconds()Description: Returns a Unix timestamp in seconds (the number elapsed since 1st Jan 1970)
Syntax: DateTime.toSeconds()
Returns: Number
Type: Luxon
Examples:
DateTime.toString()
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:
DateTime.toUTC()
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 minutesopts(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:
DateTime.weekday
DateTime.weekdayDescription: The day of the week. 1 is Monday and 7 is Sunday.
Syntax: DateTime.weekday
Returns: Number
Type: Luxon
Examples:
DateTime.weekdayLong
DateTime.weekdayLongDescription: 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:
DateTime.weekdayShort
DateTime.weekdayShortDescription: 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:
DateTime.weekNumber
DateTime.weekNumberDescription: The week number of the year (1-52ish)
Syntax: DateTime.weekNumber
Returns: Number
Type: Luxon
Examples:
DateTime.year
DateTime.yearDescription: The year
Syntax: DateTime.year
Returns: Number
Type: Luxon
Examples:
DateTime.zone
DateTime.zoneDescription: The time zone associated with the DateTime
Syntax: DateTime.zone
Returns: Object
Type: Luxon
Examples:
Last updated
Was this helpful?