Oihana PHP Arango

dateSubstract.php

Table of Contents

Functions

dateSubtract()  : string
Subtract a specified amount of time units from a date and return the resulting date.

Functions

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)
  • date can be a numeric timestamp or ISO 8601 string.
  • amount is the number of units to subtract (positive value) or add (negative value, though using DATE_ADD is preferred for additions).
  • 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 : 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
example
echo dateSubtract('2025-10-08T12:00:00Z', 3, 'day');
// Produces: DATE_SUBTRACT("2025-10-08T12:00:00Z", 3, "day")
see
https://docs.arangodb.com/stable/aql/functions/date/#date_add
since
1.0.0
author

Marc Alcaraz

Return values
string

The AQL expression returning the calculated ISO 8601 date string.

On this page

Search results