'DATE_DIFF BigQuery

DATE_DIFF(CURRENT_DATE('Europe/Paris'), 365, DAY)

Returns me error

No matching signature for function DATE_DIFF for argument types: DATE, INT64, DATE_TIME_PART. Supported signatures: DATE_DIFF(DATE, DATE, DATE_TIME_PART); DATE_DIFF(DATETIME, DATETIME, DATE_TIME_PART); DATE_DIFF(TIMESTAMP, TIMESTAMP, DATE_TIME_PART)

How to correct this ?

My regards,



Solution 1:[1]

Use below instead

SELECT DATE_SUB(CURRENT_DATE('Europe/Paris'), INTERVAL 365 DAY)    

As a shortcut, below also works

SELECT CURRENT_DATE('Europe/Paris') - 365

Solution 2:[2]

Aren't you looking for the function DATE_SUB?

DATE_SUB(CURRENT_DATE('Europe/Paris'), INTERVAL 365 DAY)

DATE_SUB substracts 365 days from the current date in Paris and returns the corresponding DATE.

DATE_DIFF in contrast returns the number (therefore an INT) of DATE_TIME_PART between 2 dates.

See here for reference.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mikhail Berlyant
Solution 2