[
https://issues.apache.org/jira/browse/CALCITE-5469?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17693531#comment-17693531
]
Julian Hyde commented on CALCITE-5469:
--------------------------------------
It is difficult to discern the rule for whether date-time functions should
truncate to the unit before they subtract. By experimentation, the rule seems
to be:
* The standard {{TIMESTAMPDIFF}} function does not truncate before subtraction;
* BigQuery functions do not truncate before subtraction when applied to time
units (e.g. {{HOUR}});
* BigQuery functions ({{TIMESTAMP_DIFF}}, {{DATETIME_DIFF}}, {{DATE_DIFF}})
truncate before subtraction when applied to date units (e.g. {{DAY}}, {{WEEK}},
{{ISOWEEK}}, {{WEEK(WEDNESDAY)}}, {{SQL_TSI_YEAR}}, {{CENTURY}}).
> Implement BigQuery DATETIME_ADD/DATETIME_DIFF
> ---------------------------------------------
>
> Key: CALCITE-5469
> URL: https://issues.apache.org/jira/browse/CALCITE-5469
> Project: Calcite
> Issue Type: Sub-task
> Reporter: Tanner Clary
> Assignee: Tanner Clary
> Priority: Major
> Labels: pull-request-available
> Time Spent: 2.5h
> Remaining Estimate: 0h
>
> Add support for BigQuery's {{DATETIME_ADD/DATETIME_DIFF}} functions.
> {{DATETIME_ADD(datetime, interval)}} can accept a timestamp (or a datetime,
> which is an alias for timestamp) for its first argument and an interval for
> its second. The output is the datetime that occurs {{interval}} after the
> provided {{datetime}}.
> {{DATETIME_DIFF(datetime, datetime2, timeUnit)}} returns the whole number of
> {{timeUnit}} between {{datetime}} and {{datetime2}}, with the result being
> negative if {{datetime}} occurs before {{datetime2}}
> Examples:
> {{DATETIME_ADD(TIMESTAMP '2008-12-25 15:30:00', INTERVAL 5 MINUTE)}} would
> return: '2008-12-25 15:35:00'.
> {{DATETIME_DIFF(DATETIME '2008-12-25 15:30:00', DATETIME '2008-12-26
> 15:30:00', DAY)}} would return: -1.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)