tg icon indicating copy to clipboard operation
tg copied to clipboard

dateOf: improved support for dates before 1753 in SQL Server

Open 01es opened this issue 10 months ago • 0 comments

Description

EQL's function dateOf gets converted to DATEADD(dd, DATEDIFF(dd, 0, <column>), 0). Due to the fact that 0 is considered by SQL Server to be of type datetime, every argument is treated as datetime. This leads to runtime errors in case the underlying data of type datetime2 includes values before 1753-01-01 (the minimum value for type datetime).

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
  • [ ] 1. Value CAST('0001-01-01' AS datetime2), which represents the minimum value for datetime2, should be used in DateOf3 instead of 0,:

    DATEADD(dd, DATEDIFF(dd, CAST('0001-01-01' AS datetime2), <column>), CAST('0001-01-01' AS datetime2))
    
  • [ ] 2. Need to inspect other date-rated EQL functions to make sure they work correctly with dates before 1753-01-01.

Note: may be of interest https://stackoverflow.com/questions/3310569/what-is-the-significance-of-1-1-1753-in-sql-server

Expected outcome

Extended range of supported date values.

01es avatar Mar 06 '25 00:03 01es