SELECT `justfunctions.eu.shift_date`("2023-01-01", -2, 1, 4)
/*--Output--
2021-02-05
*/
CREATE OR REPLACE FUNCTION `your_project_id.your_dataset_id.shift_date`(`date` DATE, `years` INT64, `months` INT64, `days` INT64)
RETURNS DATE AS (DATE_ADD(
DATE_ADD(
DATE_ADD(
date,
INTERVAL years YEAR
),
INTERVAL months MONTH
),
INTERVAL days DAY
)
)
OPTIONS ( description = '''Shifts a <date> by adding or subtracting specified <years>, <months>, and <days>. Use a minus (-) to subtract.''')
SQL User Defined Function (SQL UDF)
See something wrong? Contact us or report an issue on Github.