/ Published in: SQL
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
CREATE OR REPLACE FUNCTION dayOfWeek (DATE DATE) RETURNS CHARACTER VARYING(15) AS $$ DECLARE DAY_OF_WEEK_CONST CHARACTER VARYING(15) := 'dow'; dayOfWeek INTEGER := 0; dayName CHARACTER VARYING(15) := 'Test'; BEGIN dayOfWeek := date_part(DAY_OF_WEEK_CONST, DATE); IF dayOfWeek = 0 THEN dayName := 'Sunday'; ELSEIF dayOfWeek = 1 THEN dayName := 'Monday'; ELSEIF dayOfWeek = 2 THEN dayName := 'Tuesday'; ELSEIF dayOfWeek = 3 THEN dayName := 'Wednesday'; ELSEIF dayOfWeek = 4 THEN dayName := 'Thursday'; ELSEIF dayOfWeek = 5 THEN dayName := 'Friday'; ELSEIF dayOfWeek = 6 THEN dayName := 'Saturday'; END IF; RETURN dayName; END; $$ LANGUAGE plpgsql;