• UDF Example 

CREATE
OR
REPLACE
FUNCTION "UDF_DATES_DAYS_RANGE"(END_DATE TIMESTAMP_NTZ,
                                START_DATE TIMESTAMP_NTZ) RETURNS VARCHAR(16777216) LANGUAGE SQL
  COMMENT='Returns descriptive string for range of days between 2 timestamps'
AS
  '  CASE    

WHEN END_DATE IS NOT NULL AND START_DATE IS NOT NULL

    THEN    

     CASE          

     WHEN TIMEDIFF(D,START_DATE,END_DATE) <= 7 THEN ''0-7 Days''        

     WHEN TIMEDIFF(D,START_DATE,END_DATE) <=14 THEN ''7-14 Days''        

     WHEN TIMEDIFF(D,START_DATE,END_DATE) <= 30 THEN ''14-30 Days''        

     WHEN TIMEDIFF(D,START_DATE,END_DATE) > 30 THEN ''30+ Days''      

     ELSE ''N/A''      END  

ELSE ''N/A''  END  '