Skip to content

[Bug] TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2) get wrong result #9296

Description

@alanredsheep

Search before asking

  • I had searched in the issues and found no similar issues.

Version

0.15

What's Wrong?

# doris 0.15# timestampdiff between 1981-09-11 and 2022-04-28 should be 40 yearsSELECT TIMESTAMPDIFF(YEAR,DATE('1981-09-11'),'2022-04-28') AS`date-str`,
TIMESTAMPDIFF(YEAR,'1981-09-11','2022-04-28') AS`str-str`,
TIMESTAMPDIFF(YEAR,DATE('1981-09-11'),DATE('2022-04-28')) AS`date-date`,
TIMESTAMPDIFF(YEAR,'1981-09-11',DATE('2022-04-28')) AS`str-date`# while the result is date-str	str-str date-date str-date41404141# timestampdiff between 1981-04-11 and 2022-04-28 should be 41 yearsSELECT
TIMESTAMPDIFF(YEAR,DATE('1981-09-11'),'2022-04-28') AS`date-str`,
TIMESTAMPDIFF(YEAR,'1981-09-11','2022-04-28') AS`str-str`,
TIMESTAMPDIFF(YEAR,DATE('1981-04-11'),DATE('2022-04-28')) AS`date-date`,
TIMESTAMPDIFF(YEAR,'1981-04-11',DATE('2022-04-28')) AS`str-date`# while the result is date-str	str-str date-date str-date41404141

What You Expected?

timestampdiff between 1981-09-11 and 2022-04-28 should be 40 year
timestampdiff between 1981-04-11 and 2022-04-28 should be 41 year

Anything Else?

This also happens when unit is MONTH !
And it even get different result using TIMESTAMP(expr) instead of DATE(expr)

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions