final class DateArithmetic
    implements Scalar
    uses Snapshot
Public API: explicitly declared with @visibility public.

A call of DATE_ADD(date, INTERVAL expr unit) or DATE_SUB(date, INTERVAL expr unit).

Rule: MYSQL-DATE-ARITHMETIC-001. The server builds Item_date_add_interval. ADDDATE and SUBDATE with an INTERVAL argument are the same functions (synonyms in CallNoise) and are written as DATE_ADD and DATE_SUB. The result type follows the date and the unit (ResultTyping::dateArithmetic); the result is NULL when an operand is NULL or the date is invalid. Terminates: the operands are strict parts. Source: https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_date-add. Status: Implemented.

Typing a date plus monthsdoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze("SELECT ADDDATE(DATE '2024-01-01', INTERVAL 1 MONTH) AS d");
    [$query->field(0)->type->descriptor->name(), $query->toString()] // => ['DATE', "SELECT DATE_ADD(DATE '2024-01-01', INTERVAL 1 MONTH) AS d"]

Properties§

public bool $subtract
public Scalar $date
public Scalar $quantity

Methods§

public function __construct(
    public bool $subtract,
    public Scalar $date,
    public Scalar $quantity,
    public IntervalUnit $unit,
)

Parameters

$subtractboolWhether the interval is subtracted (DATE_SUB)
$dateScalarThe date or time
$quantityScalarThe number of units
$unitIntervalUnitThe unit
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the operands and the type the date and the unit give.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

Calls 6
public function render(Output $out): void

Writes the call.

Parameters

$outOutput
Test cases 1
Calls 1

Test cases 3§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 2
Other tests reaching this symbol 1

Relations§

Instantiated in 1