Date functions
The Date functions provide methods for creating date objects and getting various properties of the objects. The DateAdd() and DateDiff() functions are convenient for adjusting the desired date based on a specified interval. The Now() function may also be used to get the current time in the local time of the client.
Date
This function has 3 signatures:
- Date(year, month, day, hour?, minute?, second?, millisecond?) -> Date
- Date(epoch?) -> Date
- Date(timestamp?) -> Date
Date(year, month, day, hour?, minute?, second?, millisecond?) -> Date
Function bundle: Core
Creates a Date object from a set of parameters. By default, dates are created in the local time of the client or system.
Parameters
- year: Number - A number representing a year.
- month: Number - The month (0-11) where
0
is January and11
is December. - day: Number - The day of the month (1-31).
- hour (Optional): Number - The hour of the day (0-23).
- minute (Optional): Number - The minute of the hour (0-59).
- second (Optional): Number - The second of the minute (0-59).
- millisecond (Optional): Number - The millisecond of the second (0-999).
Return value: Date
Examples
Creates a date representing the given time in the local time of the system running Arcade
Creates a date representing the current time in the local time of the system running Arcade
Date(epoch?) -> Date
Function bundle: Core
Creates a date with the given Unix epoch number in the local time zone of the client or system.
Parameter
- epoch (Optional): Number - The number of milliseconds since January 1, 1970 UTC.
Return value: Date
Example
Milliseconds since January 1, 1970
Date(timestamp?) -> Date
Function bundle: Core
Converts an ISO 8601 text value to a Date object in the local time zone of the client or system.
Parameter
- timestamp (Optional): Text - An ISO 8601 text value to be converted into a date.
Return value: Date
Example
ISO 8601 text value
DateAdd
DateAdd(dateValue, addValue, units?) -> Date
Function bundle: Core
Adds a specified amount of time in the given units to a date and returns a new date.
Parameters
- dateValue: Date - The input date to which to add time.
- addValue: Number - The value to add to the date in the given units.
- units (Optional): Text - The units of the number to add to the date. Default is 'milliseconds
. The supported unit types include
milliseconds,
seconds,
minutes,
hours,
days,
months,
years`
Return value: Date
Example
Adds 7 days to the date in the provided field
DateDiff
DateDiff(date1, date2, units?) -> Number
Function bundle: Core
Subtracts two dates, and returns the difference in the specified units.
Parameters
- date1: Date - The date value from which to subtract a second date.
- date2: Date - The date value to subtract from the first given date.
- units (Optional): Text - The units in which to return the difference of the two given dates. The supported unit types include
milliseconds
,seconds
,minutes
,hours
,days
,months
,years
. The default value ismilliseconds
.
Return value: Number
Example
Subtracts two dates and returns the age
Day
Day(dateValue) -> Number
Function bundle: Core
Returns the day of the month of the given date.
Parameter
- dateValue: Date - A date value from which to get the day of the month.
Return value: Number
Example
Gets the day of the month of the current date
Hour
Hour(dateValue) -> Number
Function bundle: Core
Returns the hour of the time in the given date (0-23).
Parameter
- dateValue: Date - A date value from which to get the hour of the time.
Return value: Number
Example
Gets the hour of the current time
ISOMonth
ISOMonth(dateValue) -> Number
Function bundle: Core
Returns the month of the given date, based on the ISO 8601 standard. Values range from 1-12 where January is 1
and December is 12
.
Parameter
- dateValue: Date - A date value from which to get the month.
Return value: Number
Example
Gets the month of the given date, based on the ISO 8601 standard. Returns 12
, for the month of December.
ISOWeek
ISOWeek(dateValue) -> Number
Function bundle: Core
Returns the week in the year of the given date, based on the ISO 8601 week date calendar. Values range from 1-53 where the first week of the year is 1
and the last week of the year is 52
or 53
, depending on the year.
Parameter
- dateValue: Date - A date value from which to get the week.
Return value: Number
Example
Gets the week of the given date, based on the ISO 8601 standard. Returns 1
, since this date is included in the first week of the following year.
ISOWeekday
ISOWeekday(dateValue) -> Number
Function bundle: Core
Returns the day of the week of the given date, based on the ISO 8601 standard. Values range from 1-7 where Monday is 1
and Sunday is 7
.
Parameter
- dateValue: Date - A date value from which to return the day of the week.
Return value: Number
Example
Returns the day of the week of the given date, based on the ISO 8601 standard. Returns 3
, for Wednesday.
ISOYear
ISOYear(dateValue) -> Number
Function bundle: Core
Returns the year of the given date based on the ISO 8601 week date calendar.
Parameter
- dateValue: Date - A date value from which to get the year.
Return value: Number
Example
Gets the year of the given date, based on the ISO 8601 week date calendar. Returns 1981
, since this date is included in the first week of the following year.
Millisecond
Millisecond(dateValue) -> Number
Function bundle: Core
Returns the millisecond of the time in the date.
Parameter
- dateValue: Date - A date value from which to get the millisecond of the time.
Return value: Number
Example
Gets the millisecond of the current time
Minute
Minute(dateValue) -> Number
Function bundle: Core
Returns the minute of the time in the given date.
Parameter
- dateValue: Date - A date value from which to get the minute of the time.
Return value: Number
Example
Gets the minute of the current time
Month
Month(dateValue) -> Number
Function bundle: Core
Returns the month of the given date. Values range from 0-11 where January is 0
and December is 11
.
Parameter
- dateValue: Date - A date value from which to get the month.
Return value: Number
Example
Gets the month of the given Date. Returns 11, for the month of December.
Now
Now() -> Date
Function bundle: Core
Creates a date value in the local or system time of the client.
Return value: Date
Example
Returns the current date and time
Second
Second(dateValue) -> Number
Function bundle: Core
Returns the second of the time in the date.
Parameter
- dateValue: Date - A date value from which to get the second of the time.
Return value: Number
Example
Gets the second of the current time
Timestamp
Timestamp() -> Date
Function bundle: Core
Creates a date value representing the current date and time in UTC.
Return value: Date
Example
Creates a date in UTC time
Today
Today() -> Date
Function bundle: Core
Returns the current date in the local time of the client.
Return value: Date
Example
Returns the current date with time truncated, e.g. Mon Oct 24 2016 00:00:00 GMT-0700 (PDT)
ToLocal
ToLocal(inputDate) -> Date
Function bundle: Core
Creates a new date value matching the epoch of the input date and sets the time zone to the local or system time zone of the client.
Parameter
- inputDate: Date - A date value to convert to the local time of the client.
Return value: Date
Example
Converts a UTC date to the local time of the client
ToUTC
ToUTC(inputDate) -> Date
Function bundle: Core
Creates a new date value matching the epoch of the input date and sets the time zone to UTC.
Parameter
- inputDate: Date - A date value to convert to UTC time.
Return value: Date
Example
Converts the date object from local time to UTC
Week
Week(dateValue, startDay?) -> Number
Function bundle: Core
Returns the week number in the year of the given date. Values range from 0-53 where the first week of the year is 0
and the last week of the year is 51
, 52
, or 53
, depending on the year. The first and last weeks may not be a full seven days in length.
Parameters
- dateValue: Date - A date value from which to get the week.
- startDay (Optional): Number - A number representing the start day of the week. Sunday = 0; Monday = 1; Tuesday = 2; Wednesday = 3; Thursday = 4; Friday = 5; Saturday = 6. The default is
0
(Sunday).
Return value: Number
Examples
Use the default start of the week (Sunday)
Set start of week to Thursday
Set start of week to Friday
Weekday
Weekday(dateValue) -> Number
Function bundle: Core
Returns the day of the week of the given date. Values range from 0-6 where Sunday is 0
and Saturday is 6
.
Parameter
- dateValue: Date - A date value from which to return the day of the week.
Return value: Number
Example
Returns the day of the week of the given date. Returns 3
, for Wednesday.
Year
Year(dateValue) -> Number
Function bundle: Core
Returns the year of the given date.
Parameter
- dateValue: Date - A date value from which to get the year.
Return value: Number
Example
Gets the year of the current date