DATEDIFF UDF
Description
This UDF is used as a template for all cases when there is a subtraction between a DATE, TIMESTAMP, and any other type (except Intervals).
Custom UDF overloads
DATEDIFF_UDF(date, date)
Parameters
FIRST_PARAM: The first
DATEof the operation.SECOND_PARAM: The
DATEto be subtracted.
CREATE OR REPLACE FUNCTION PUBLIC.DATEDIFF_UDF(FIRST_PARAM DATE, SECOND_PARAM DATE)
RETURNS INTEGER
LANGUAGE SQL
IMMUTABLE
COMMENT = '{"origin":"sf_sc","name":"snowconvert","version":{"major":1, "minor":0},"attributes":{"component":"udf"}}'
AS
$$
FIRST_PARAM - SECOND_PARAM
$$;DATEDIFF_UDF(date, timestamp)
Parameters
FIRST_PARAM: The first
DATEof the operation.SECOND_PARAM: The
TIMESTAMPto be subtracted.
DATEDIFF_UDF(date, integer)
Parameters
FIRST_PARAM: The first
DATEof the operation.SECOND_PARAM: The
INTEGERto be subtracted.
DATEDIFF_UDF(timestamp, timestamp)
Parameters
FIRST_PARAM: The first
TIMESTAMPof the operation.SECOND_PARAM: The
TIMESTAMPto be subtracted.
DATEDIFF_UDF(timestamp, date)
Parameters
FIRST_PARAM: The first
TIMESTAMPof the operation.SECOND_PARAM: The
DATEto be subtracted.
DATEDIFF_UDF(timestamp, number)
Parameters
FIRST_PARAM: The first
TIMESTAMPof the operation.SECOND_PARAM: The
NUMBERto be subtracted.
Usage example
--disableDateAsTimestamp
--disableDateAsTimestampFlag to indicate whether SYSDATE should be transformed into CURRENT_DATE or CURRENT_TIMESTAMP. This will also affect all DATE columns that will be transformed to TIMESTAMP.
Oracle
Snowflake
Known Issues
1. Functional differences for timestamps
Sometimes the Snowflake value returned by the UDF may differ from the Oracle one due to the time. Consider the following example
Oracle
Snowflake
Related EWIs
SSC-EWI-OR0036: Types resolution issues, the arithmetic operation may not behave correctly between string and date.
Last updated