Return to Snippet

Revision: 4019
at October 16, 2007 22:45 by arunpjohny


Initial Code
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;

Initial URL

                                

Initial Description

                                

Initial Title
Get name of the weekday of a date in Postgresql

Initial Tags

                                

Initial Language
SQL