Return to Snippet

Revision: 4018
at October 16, 2007 22:44 by arunpjohny


Initial Code
CREATE OR REPLACE FUNCTION year (date1 Date) RETURNS integer AS $$
DECLARE
	YEAR_CONST Character Varying(15) := 'year';

	yearPart Integer := 0;
	yearPartInDoublePrecision Double Precision := 0;
BEGIN
	
	yearPartInDoublePrecision := date_part(YEAR_CONST, date1);

	yearPart := CAST(yearPartInDoublePrecision as Integer);
	RETURN yearPart;
END;
$$ LANGUAGE plpgsql;

Initial URL

                                

Initial Description
This kind of functions will be use full if we are migrating a database from one provider to another like from MS SQL Server to Postgresql.

Initial Title
Function to get year from a date in Postgresql

Initial Tags

                                

Initial Language
SQL