Difference in days between two dates in a 360 day year with 30 day months in Teradata

REPLACE FUNCTION DIFF360(date1 DATE, date2 DATE)
RETURNS INTEGER
RETURNS NULL ON NULL INPUT
CONTAINS SQL
DETERMINISTIC
COLLATION INVOKER
INLINE TYPE 1
RETURN
360 * (EXTRACT(YEAR FROM date1) - EXTRACT(YEAR FROM date2)) +
30 * (EXTRACT(MONTH FROM date1) - EXTRACT(MONTH FROM date2)) +
CASE WHEN EXTRACT(DAY FROM date1) > 30 THEN 30 ELSE EXTRACT(DAY FROM date1) END -
CASE WHEN EXTRACT(DAY FROM date2) > 30 THEN 30 ELSE EXTRACT(DAY FROM date2) END;