Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yogonza524/9c3787fef55748793208 to your computer and use it in GitHub Desktop.
Save yogonza524/9c3787fef55748793208 to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION date_arg_format(fecha date)
RETURNS CHARACTER VARYING AS $$
DECLARE
mes double precision;
mes_salida character varying(20);
BEGIN
IF (fecha IS NOT NULL) THEN
mes = date_part('month',fecha);
CASE mes
WHEN 1 THEN mes_salida = 'Enero';
WHEN 2 THEN mes_salida = 'Febrero';
WHEN 3 THEN mes_salida = 'Marzo';
WHEN 4 THEN mes_salida = 'Abril';
WHEN 5 THEN mes_salida = 'Mayo';
WHEN 6 THEN mes_salida = 'Junio';
WHEN 7 THEN mes_salida = 'Julio';
WHEN 8 THEN mes_salida = 'Agosto';
WHEN 9 THEN mes_salida = 'Septiembre';
WHEN 10 THEN mes_salida = 'Octubre';
WHEN 11 THEN mes_salida = 'Noviembre';
WHEN 12 THEN mes_salida = 'Diciembre';
END CASE;
ELSE
RAISE EXCEPTION 'La fecha es nula, no se puede castear';
END IF;
RETURN date_part('day',fecha) || ' de ' || mes_salida || ' de ' || date_part('year',fecha);
END;
$$
LANGUAGE PLPGSQL
@yogonza524
Copy link
Author

Ej: "1 de Diciembre de 2015".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment