databendlabs / databend

𝗗𝗮𝘁𝗮, 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀 & 𝗔𝗜. Modern alternative to Snowflake. Cost-effective and simple for massive-scale analytics. https://databend.com
https://docs.databend.com
Other
7.86k stars 751 forks source link

feature: DATE_DIFF function #16534

Closed BohuTANG closed 3 weeks ago

BohuTANG commented 1 month ago

Summary

Databend lacks a DATE_DIFF function, though it supports direct arithmetic on dates and times (e.g., TO_DATE(NOW()) - 2 for two days ago). However, users may find this conversion difficult, see: https://docs.databend.com/sql/sql-functions/datetime-functions/date-diff

Proposal add a DATE_DIFF function:

DATE_DIFF(<date_or_time_part>, <date_or_time_expr1>, <date_or_time_expr2>)

Similar to Snowflake's DATEDIFF function, this will simplify date and time arithmetic for users.

chagelo commented 1 month ago

I would like to have a try.

chagelo commented 1 month ago
  1. Should select to_date('2024-02-29') + - to_date('2025-02-28'); be valid or invalid? I mean the add operation between two date.
TCeason commented 1 month ago
  1. Should select to_date('2024-02-29') + - to_date('2025-02-28'); be valid or invalid? I mean the add operation between two date.

select to_date('2024-02-29') - to_date('2025-02-28'); is valid.

select to_date('2024-02-29') + to_date('2025-02-28'); is invalid.

TCeason commented 3 weeks ago

https://github.com/databendlabs/databend/pull/16560