Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature][SDK] Transform SQL supports DATE_ADD function #11079

Closed
2 tasks done
Zkplo opened this issue Sep 11, 2024 · 0 comments · Fixed by #11177
Closed
2 tasks done

[Feature][SDK] Transform SQL supports DATE_ADD function #11079

Zkplo opened this issue Sep 11, 2024 · 0 comments · Fixed by #11177
Assignees
Milestone

Comments

@Zkplo
Copy link
Contributor

Zkplo commented Sep 11, 2024

Description

DATE_ADD(date,INTERVAL expr unit):
The date argument specifies the starting date or datetime value. expr is an expression specifying the interval value to be added from the starting date. expr is evaluated as a string; it may start with a - for negative intervals. unit is a keyword indicating the units in which the expression should be interpreted.

Regarding the INTERVAL statement, please refer to: #11081

The return value depends on the arguments:

  • If date is NULL, the function returns NULL.

  • DATE if the date argument is a DATE value and your calculations involve only YEAR, MONTH, and DAY parts (that is, no time parts).

  • TIME if the date argument is a TIME value and the calculations involve only HOURS, MINUTES, and SECONDS parts (that is, no date parts).

  • DATETIME if the first argument is a DATETIME (or TIMESTAMP) value, or if the first argument is a DATE and the unit value uses HOURS, MINUTES, or SECONDS, or if the first argument is of type TIME and the unit value uses YEAR, MONTH, or DAY.

  • If the first argument is a dynamic parameter (for example, of a prepared statement), its resolved type is DATE if the second argument is an interval that contains some combination of YEAR, MONTH, or DAY values only; otherwise, its type is DATETIME.

  • String otherwise (type VARCHAR).

Use case

DATE_ADD('2018-05-01',INTERVAL 1 DAY)                                            -> '2018-05-02'
DATE_ADD('2020-12-31 23:59:59',  INTERVAL 1 SECOND);                             -> '2021-01-01 00:00:00'
DATE_ADD('2018-12-31 23:59:59', INTERVAL 1 DAY);                                 -> '2019-01-01 23:59:59'
DATE_ADD('2100-12-31 23:59:59', INTERVAL '1:1' MINUTE_SECOND);                   -> '2101-01-01 00:01:00'
DATE_ADD('1900-01-01 00:00:00', INTERVAL '-1 10' DAY_HOUR);                      -> '1899-12-30 14:00:00'
DATE_ADD('1992-12-31 23:59:59.000002', INTERVAL '1.999999' SECOND_MICROSECOND);  -> '1993-01-01 00:00:01.000001'

Are you willing to submit PR?

  • Yes, I am willing to submit a PR!

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants