From 210efe162113d74f3894bacd8e6a4b4a5fce975c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kudzia?= <30438339+pakud@users.noreply.github.com> Date: Mon, 15 Apr 2024 08:50:01 +0200 Subject: [PATCH] documenting alternative syntax that's supported for DATE_ADD, DATE_SUB this is related to issue https://github.com/ClickHouse/ClickHouse/issues/25815 i'm adding examples for: date_add(date, INTERVAL value unit) and date_sub(date, INTERVAL value unit) both are covered with a test from https://github.com/ClickHouse/ClickHouse/blob/e3c09e97034b7d26b2280487fa8422a8037caa51/tests/queries/0_stateless/02160_special_functions.sql#L33 ; i think it's worth documenting them as the syntax is familiar to MySQL users [ https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-add ] --- .../functions/date-time-functions.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/docs/en/sql-reference/functions/date-time-functions.md b/docs/en/sql-reference/functions/date-time-functions.md index 3bb9d4e7dbe..7c790e739e0 100644 --- a/docs/en/sql-reference/functions/date-time-functions.md +++ b/docs/en/sql-reference/functions/date-time-functions.md @@ -1902,6 +1902,12 @@ If the addition results in a value outside the bounds of the data type, the resu date_add(unit, value, date) ``` +Alternative syntax: + +``` sql +date_add(date, INTERVAL value unit) +``` + Aliases: `dateAdd`, `DATE_ADD`. **Arguments** @@ -1941,6 +1947,20 @@ Result: └───────────────────────────────────────────────┘ ``` +```sql +SELECT date_add(toDate('2018-01-01'), INTERVAL 3 YEAR); +``` + +Result: + +```text +┌─plus(toDate('2018-01-01'), toIntervalYear(3))─┐ +│ 2021-01-01 │ +└───────────────────────────────────────────────┘ +``` + + + **See Also** - [addDate](#addDate) @@ -1957,6 +1977,13 @@ If the subtraction results in a value outside the bounds of the data type, the r date_sub(unit, value, date) ``` +Alternative syntax: + +``` sql +date_sub(date, INTERVAL value unit) +``` + + Aliases: `dateSub`, `DATE_SUB`. **Arguments** @@ -1997,6 +2024,19 @@ Result: └────────────────────────────────────────────────┘ ``` +``` sql +SELECT date_sub(toDate('2018-01-01'), INTERVAL 3 YEAR); +``` + +Result: + +``` text +┌─minus(toDate('2018-01-01'), toIntervalYear(3))─┐ +│ 2015-01-01 │ +└────────────────────────────────────────────────┘ +``` + + **See Also** - [subDate](#subDate)