jueves, 5 de septiembre de 2013

Weekday in PostgreSQL

    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;

No hay comentarios:

Publicar un comentario