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

DATE_DIFF_UDF(date, date)

Parameters

  1. FIRST_PARAM: The first DATE of the operation.

  2. SECOND_PARAM: The DATE to be subtracted.

CREATE OR REPLACE FUNCTION PUBLIC.DATE_DIFF_UDF(FIRST_PARAM DATE, SECOND_PARAM DATE)
RETURNS INTEGER
LANGUAGE SQL
IMMUTABLE
AS
$$
	FIRST_PARAM - SECOND_PARAM
$$;

DATE_DIFF_UDF(date, timestamp)

Parameters

  1. FIRST_PARAM: The first DATE of the operation.

  2. SECOND_PARAM: The TIMESTAMP to be subtracted.

DATE_DIFF_UDF(date, integer)

Parameters

  1. FIRST_PARAM: The first DATE of the operation.

  2. SECOND_PARAM: The INTEGER to be subtracted.

DATE_DIFF_UDF(timestamp, timestamp)

Parameters

  1. FIRST_PARAM: The first TIMESTAMP of the operation.

  2. SECOND_PARAM: The TIMESTAMP to be subtracted.

DATE_DIFF_UDF(timestamp, date)

Parameters

  1. FIRST_PARAM: The first TIMESTAMP of the operation.

  2. SECOND_PARAM: The DATE to be subtracted.

DATE_DIFF_UDF(timestamp, number)

Parameters

  1. FIRST_PARAM: The first TIMESTAMP of the operation.

  2. SECOND_PARAM: The NUMBER to be subtracted.

Usage example

The unknown is a column whose type could not be resolved, it could be a timestamp, date integer, or number.

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

  1. MSCEWI1020: CUSTOM UDF INSERTED.

Last updated

Was this helpful?