dates
Table of Contents
Functions
- dateAdd() : string
- Adds a specified amount of time to a given date and returns the resulting ISO 8601 date string.
- dateCompare() : string
- Check if two partial dates match.
- dateDay() : string
- Returns the day of a given date.
- dateDayOfWeek() : string
- Returns the weekday number of a given date.
- dateDayOfYear() : string
- Returns the day number within the year for a given date.
- dateDaysInMonth() : string
- Returns the number of days in the month of a given date.
- dateDiff() : string
- Calculate the difference between two dates in given time unit, optionally with decimal places.
- dateFormat() : string
- Format a date according to a specified format string.
- dateHour() : string
- Returns the hour of a given date.
- dateISO8601() : string
- Converts a given date to an ISO 8601 formatted string.
- dateIsoWeek() : string
- Returns the ISO week number of a given date.
- dateIsoWeekYear() : string
- Returns the ISO week-numbering year of a given date.
- dateLeapYear() : string
- Returns whether the year of a given date is a leap year.
- dateLocalToUTC() : string
- Converts a local date/time from a specified timezone to UTC.
- dateMillisecond() : string
- Returns the millisecond (0–999) of a given date.
- dateMinute() : string
- Returns the minute (0–59) of a given date.
- dateMonth() : string
- Returns the month (1–12) of a given date.
- dateNow() : string
- Returns the current Unix timestamp (milliseconds since epoch).
- dateQuarter() : string
- Returns the quarter (1–4) of a given date.
- dateSecond() : string
- Returns the second of a given date.
- dateSubtract() : string
- Subtract a specified amount of time units from a date and return the resulting date.
- dateTimeStamp() : string
- Converts a given date into a numeric timestamp with millisecond precision.
- dateTimezone() : string
- Returns the timezone of a date value.
- dateTimezones() : string
- Returns a list of all valid timezone names known to ArangoDB.
- dateTrunc() : string
- Truncates the given date to the specified unit and returns the modified ISO 8601 date string.
- dateUTCToLocal() : string
- Converts a UTC (Zulu time) date or timestamp into a local timezone date.
- dateYear() : string
- Return the year component of a given date.
- timeUnit() : string
- Returns a valid date/time unit string expression for use in AQL functions.
- tomorrow() : string
- Return the date corresponding to "tomorrow" based on the given date or the current date.
- yesterday() : string
- Return the date corresponding to "yesterday" based on the given date or the current date.
Functions
dateAdd()
Adds a specified amount of time to a given date and returns the resulting ISO 8601 date string.
dateAdd(string|int|null $date, string|int $amount[, string $unit = DateUnit::DAY ]) : string
Constructs an AQL expression in the format:
DATE_ADD(date, amount, unit)
where date can be a numeric timestamp or ISO 8601 string, amount is the number
of units to add (or subtract if negative), and unit specifies the time unit.
Supported units (case-insensitive):
- y, year, years
- m, month, months
- w, week, weeks
- d, day, days
- h, hour, hours
- i, minute, minutes
- s, second, seconds
- f, millisecond, milliseconds
Parameters
- $date : string|int|null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null. - $amount : string|int
-
Number of units to add (positive) or subtract (negative). Positive values recommended.
- $unit : string = DateUnit::DAY
-
Time unit to add (default:
"day").
Tags
Return values
string —The AQL expression returning the calculated ISO 8601 date string.
dateCompare()
Check if two partial dates match.
dateCompare([string|int|null $date1 = null ][, string|int|null $date2 = null ][, string|null $unitRangeStart = 'y' ][, string|null $unitRangeEnd = null ]) : string
DATE_COMPARE(date1, date2, unitRangeStart, unitRangeEnd) → bool returns bool (bool): true if the dates match, false otherwise All components of date1 and date2 as specified by the range will be compared. You can refer to the units as:
- y, year, years
- m, month, months
- d, day, days
- h, hour, hours
- i, minute, minutes
- s, second, seconds
- f, millisecond, milliseconds
Parameters
- $date1 : string|int|null = null
-
- numeric timestamp or ISO 8601 date time string
- $date2 : string|int|null = null
-
- numeric timestamp or ISO 8601 date time string
- $unitRangeStart : string|null = 'y'
-
- unit to start from, see below
- $unitRangeEnd : string|null = null
-
- unit to end with, leave out to only compare the component as specified by unitRangeStart. An error is raised if unitRangeEnd is a unit before unitRangeStart.
Return values
stringdateDay()
Returns the day of a given date.
dateDay([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_DAY(date)
where date can be a numeric timestamp or an ISO 8601 date string.
The result is a number representing the day of the month (1–31).
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the day as a number.
dateDayOfWeek()
Returns the weekday number of a given date.
dateDayOfWeek([string|int|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_DAYOFWEEK(date) → dayOfWeek
Returns a number between 0 and 6:
- 0 – Sunday
- 1 – Monday
- 2 – Tuesday
- 3 – Wednesday
- 4 – Thursday
- 5 – Friday
- 6 – Saturday
Parameters
- $date : string|int|null = null
-
A numeric timestamp or ISO 8601 date string. If null, uses
dateNow().
Tags
Return values
string —The AQL expression returning the weekday number.
dateDayOfYear()
Returns the day number within the year for a given date.
dateDayOfYear([string|int|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_DAYOFYEAR(date) → dayOfYear
Returns a number from 1 to 365 (or 366 for leap years).
Parameters
- $date : string|int|null = null
-
A numeric timestamp or ISO 8601 date string. If null, uses
dateNow().
Tags
Return values
string —The AQL expression returning the day of year.
dateDaysInMonth()
Returns the number of days in the month of a given date.
dateDaysInMonth([string|int|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_DAYS_IN_MONTH(date) → daysInMonth
Returns a number between 28 and 31 depending on the month and leap years.
Parameters
- $date : string|int|null = null
-
A numeric timestamp or ISO 8601 date string. If null, uses
dateNow().
Tags
Return values
string —The AQL expression returning the number of days in the month.
dateDiff()
Calculate the difference between two dates in given time unit, optionally with decimal places.
dateDiff([string|int|null $date1 = null ][, string|int|null $date2 = null ][, string $unit = DateUnit::DAY ][, bool $asFloat = null ][, string|null $timezone1 = null ][, string|null $timezone2 = null ]) : string
Parameters
- $date1 : string|int|null = null
-
numeric timestamp or ISO 8601 date time string
- $date2 : string|int|null = null
-
numeric timestamp or ISO 8601 date time string
- $unit : string = DateUnit::DAY
-
either of the following to specify the time unit to return the difference in (case-insensitive):
- "y", "year", "years"
- "m", "month", "months"
- "w", "week", "weeks"
- "d", "day", "days"
- "h", "hour", "hours"
- "i", "minute", "minutes"
- "s", "second", "seconds"
- "f", "millisecond", "milliseconds"
- $asFloat : bool = null
-
if set to true, decimal places will be preserved in the result. The default is false and an integer is returned.
- $timezone1 : string|null = null
-
if set, date1 is assumed to be in the specified timezone. If timezone2 is not set, then both date1 and date2 are assumed to be in the timezone specified by timezone1, e.g. "America/New_York", "Europe/Berlin", or "UTC". Use "America/Los_Angeles" for Pacific time (PST/PDT).
- $timezone2 : string|null = null
-
if set, date2 is assumed to be in the timezone specified by timezone2, and date1 is assumed to be in the timezone specified by timezone1, e.g. "America/New_York", "Europe/Berlin", or "UTC". Use "America/Los_Angeles" for Pacific time (PST/PDT).
Return values
stringdateFormat()
Format a date according to a specified format string.
dateFormat([null|string|int $date = null ][, string $format = DateFormat::ISO8601 ][, bool $useQuotes = true ]) : string
Constructs an AQL expression in the format:
DATE_FORMAT(date, format)
The format string supports the following placeholders (case-insensitive):
- %t – timestamp in milliseconds since 1970-01-01T00:00:00Z
- %z – ISO date (0000-00-00T00:00:00.000Z)
- %w – day of week (0..6)
- %y – year (0..9999)
- %yy – last two digits of year
- %yyyy – padded year (0000..9999)
- %yyyyyy – signed and padded year (-009999..+009999)
- %m – month (1..12)
- %mm – month padded to 2 digits
- %d – day (1..31)
- %dd – day padded to 2 digits
- %h – hour (0..23)
- %hh – hour padded to 2 digits
- %i – minute (0..59)
- %ii – minute padded to 2 digits
- %s – second (0..59)
- %ss – second padded to 2 digits
- %f – millisecond (0..999)
- %fff – millisecond padded to 3 digits
- %x – day of year (1..366)
- %xxx – day of year padded to 3 digits
- %k – ISO week number (1..53)
- %kk – ISO week number padded to 2 digits
- %l – leap year (0 or 1)
- %q – quarter (1..4)
- %a – days in month (28..31)
- %mmm – abbreviated English month name (Jan..Dec)
- %mmmm – full English month name (January..December)
- %www – abbreviated English weekday name (Sun..Sat)
- %wwww – full English weekday name (Sunday..Saturday)
- %& – special escape sequence
- %% – literal %
- % – ignored
Parameters
- $date : null|string|int = null
-
A numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null. - $format : string = DateFormat::ISO8601
-
Format string using placeholders (default:
DateFormat::ISO8601). - $useQuotes : bool = true
-
Whether to wrap the expression (default: true).
Tags
Return values
string —AQL expression returning the formatted date string.
dateHour()
Returns the hour of a given date.
dateHour([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_HOUR(date)
where date can be a numeric timestamp or an ISO 8601 date string.
The result is a number representing the hour (0–23).
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the hour as a number.
dateISO8601()
Converts a given date to an ISO 8601 formatted string.
dateISO8601([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_ISO8601(date)
where date can be a numeric timestamp or an ISO 8601 date-time string.
The return value is a string in ISO 8601 format.
Parameters
- $date : int|string|null = null
-
A numeric timestamp or ISO 8601 date string. If null, uses
DATE_NOW().
Tags
Return values
string —The AQL expression returning the ISO 8601 date string.
dateIsoWeek()
Returns the ISO week number of a given date.
dateIsoWeek([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_ISOWEEK(date)
where date can be a numeric timestamp or an ISO 8601 date string.
The result is a number representing the ISO week of the year (1–53).
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the ISO week number.
dateIsoWeekYear()
Returns the ISO week-numbering year of a given date.
dateIsoWeekYear([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_ISOWEEKYEAR(date)
where date can be a numeric timestamp or an ISO 8601 date string.
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the ISO week-numbering year.
dateLeapYear()
Returns whether the year of a given date is a leap year.
dateLeapYear([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_LEAPYEAR(date)
where date can be a numeric timestamp or an ISO 8601 date string.
The result is a boolean: true if it is a leap year, false otherwise.
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning a boolean indicating leap year.
dateLocalToUTC()
Converts a local date/time from a specified timezone to UTC.
dateLocalToUTC([int|string|null $date = null ][, string $timezone = "UTC" ][, bool $throwable = true ]) : string
Constructs an AQL expression in the format:
DATE_LOCALTOUTC(date, timezone)
where date can be a numeric timestamp or ISO 8601 string, and timezone is a valid IANA timezone name.
If $date is null, the current date/time (DATE_NOW()) is used.
By default, throws an InvalidArgumentException if the $timezone is not a valid IANA timezone.
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null. - $timezone : string = "UTC"
-
IANA timezone name (e.g., "Europe/Paris", "America/New_York").
- $throwable : bool = true
-
Whether to throw an exception on invalid timezone (default: true).
Tags
Return values
string —The AQL expression returning the date converted to UTC.
dateMillisecond()
Returns the millisecond (0–999) of a given date.
dateMillisecond([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_MILLISECOND(date)
where date can be a numeric timestamp or an ISO 8601 date string.
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the millisecond.
dateMinute()
Returns the minute (0–59) of a given date.
dateMinute([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_MINUTE(date)
where date can be a numeric timestamp or an ISO 8601 date string.
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the minute as a number.
dateMonth()
Returns the month (1–12) of a given date.
dateMonth([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_MONTH(date)
where date can be a numeric timestamp or an ISO 8601 date string.
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the month as a number (1–12).
dateNow()
Returns the current Unix timestamp (milliseconds since epoch).
dateNow() : string
This helper builds the AQL expression:
DATE_NOW()
It is equivalent to calling DATE_NOW() in AQL, which returns the
current UTC timestamp as a numeric value representing milliseconds since
January 1, 1970 (Unix epoch).
Tags
Return values
string —The AQL expression string "DATE_NOW()".
dateQuarter()
Returns the quarter (1–4) of a given date.
dateQuarter([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_QUARTER(date)
where date can be a numeric timestamp or an ISO 8601 date string.
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the quarter as a number (1–4).
dateSecond()
Returns the second of a given date.
dateSecond([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_SECOND(date)
where date can be a numeric timestamp or an ISO 8601 date string.
The result is a number representing the second (0–59).
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the second as a number.
dateSubtract()
Subtract a specified amount of time units from a date and return the resulting date.
dateSubtract(int|string|null $date, int|string $amount[, string $unit = DateUnit::DAY ]) : string
Constructs an AQL expression in the format:
DATE_SUBTRACT(date, amount, unit)
datecan be a numeric timestamp or ISO 8601 string.amountis the number of units to subtract (positive value) or add (negative value, though using DATE_ADD is preferred for additions).unitspecifies the time unit.
Supported units (case-insensitive):
- y, year, years
- m, month, months
- w, week, weeks
- d, day, days
- h, hour, hours
- i, minute, minutes
- s, second, seconds
- f, millisecond, milliseconds
Parameters
- $date : int|string|null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null. - $amount : int|string
-
Number of units to subtract (positive) or add (negative).
- $unit : string = DateUnit::DAY
-
Time unit (default:
"day").
Tags
Return values
string —The AQL expression returning the calculated ISO 8601 date string.
dateTimeStamp()
Converts a given date into a numeric timestamp with millisecond precision.
dateTimeStamp([int|string|null $date = null ]) : string
Constructs an AQL expression in the format:
DATE_TIMESTAMP(date)
where date can be a numeric timestamp or an ISO 8601 date string.
The result is a numeric timestamp in milliseconds. To obtain seconds, divide the result by 1000.
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the timestamp.
dateTimezone()
Returns the timezone of a date value.
dateTimezone() : string
Constructs an AQL expression in the format:
DATE_TIMEZONE()
Tags
Return values
string —AQL expression returning the timezone string of a date.
dateTimezones()
Returns a list of all valid timezone names known to ArangoDB.
dateTimezones() : string
Constructs an AQL expression in the format:
DATE_TIMEZONES()
Tags
Return values
string —AQL expression returning an array of timezone strings.
dateTrunc()
Truncates the given date to the specified unit and returns the modified ISO 8601 date string.
dateTrunc([string|int|null $date = null ][, string|null $unit = DateUnit::MONTH ]) : string
Constructs an AQL expression in the format:
DATE_TRUNC(date, unit)
where date can be a numeric timestamp or ISO 8601 string, and unit specifies
the precision to truncate to.
Supported units (case-insensitive):
- y, year, years
- m, month, months (default)
- d, day, days
- h, hour, hours
- i, minute, minutes
- s, second, seconds
- f, millisecond, milliseconds
Parameters
- $date : string|int|null = null
-
The date to truncate. If null, the current timestamp (
DATE_NOW()) is used. - $unit : string|null = DateUnit::MONTH
-
The time unit to truncate to (default:
"month").
Tags
Return values
string —The AQL expression returning the truncated ISO 8601 date string.
dateUTCToLocal()
Converts a UTC (Zulu time) date or timestamp into a local timezone date.
dateUTCToLocal([string|int|null $date = null ][, string $timezone = "Europe/Paris" ][, bool $throwable = false ]) : string
Constructs an AQL expression in the form:
DATE_UTCTOLOCAL(date, timezone, zoneinfo)
Converts a UTC timestamp or ISO 8601 string into the specified local time zone.
If no date is provided, the current time (DATE_NOW()) is used.
By default, throws an InvalidArgumentException if the $timezone is not a valid IANA timezone.
Parameters
- $date : string|int|null = null
-
A numeric timestamp or ISO 8601 date-time string. Defaults to
DATE_NOW()if null. - $timezone : string = "Europe/Paris"
-
IANA timezone name (e.g.,
"America/New_York","Europe/Berlin","UTC"). Use"America/Los_Angeles"for Pacific Time (PST/PDT). - $throwable : bool = false
-
Whether to throw an exception on invalid timezone (default: true).
Tags
Return values
string —The AQL expression returning the date converted from UTC to the specified local time zone.
dateYear()
Return the year component of a given date.
dateYear([string|int|null $date = null ]) : string
Constructs an AQL expression equivalent to:
DATE_YEAR(date)
If no date is provided, the current date (DATE_NOW()) is used.
Parameters
- $date : string|int|null = null
-
A numeric timestamp or ISO 8601 date-time string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the year part of the given date as a number.
timeUnit()
Returns a valid date/time unit string expression for use in AQL functions.
timeUnit([string|null $unit = DateUnit::DAY ]) : string
This helper ensures the provided $unit is a valid time unit among:
year(s), month(s), day(s), hour(s), minute(s), second(s), or millisecond(s).
If the value is not recognized, it defaults to "day".
Example AQL usage:
DATE_ADD(date, 3, "day")
DATE_SUBTRACT(date, 2, "month")
Parameters
- $unit : string|null = DateUnit::DAY
-
One of the following units (case-insensitive):
y,year,yearsm,month,months(default)d,day,daysh,hour,hoursi,minute,minutess,second,secondsf,millisecond,milliseconds
Tags
Return values
string —The quoted valid time unit (e.g. "day").
tomorrow()
Return the date corresponding to "tomorrow" based on the given date or the current date.
tomorrow([int|string|null $date = null ]) : string
Constructs an AQL expression equivalent to:
DATE_ADD(date, 1, "day")
If no date is provided, the current date (from DATE_NOW()) is used as the reference point.
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the ISO 8601 string for the date of tomorrow.
yesterday()
Return the date corresponding to "yesterday" based on the given date or the current date.
yesterday([int|string|null $date = null ]) : string
Constructs an AQL expression equivalent to:
DATE_SUBTRACT(date, 1, "day")
If no date is provided, the current date (from DATE_NOW()) is used as the reference point.
Parameters
- $date : int|string|null = null
-
Numeric timestamp or ISO 8601 date string. Defaults to
DATE_NOW()if null.
Tags
Return values
string —The AQL expression returning the ISO 8601 string for the date of yesterday.