Skip to content

Instantly share code, notes, and snippets.

@jhargis
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhargis/5c6c6b75fee46725b686 to your computer and use it in GitHub Desktop.
Save jhargis/5c6c6b75fee46725b686 to your computer and use it in GitHub Desktop.
Convert Clarion date values from 5 digit integers to DATE types in Postgresql with a custom function
# Convert Clarion date values from 5 digit integers to DATE types in Postgresql with a custom function
\d inv
Table "public.inv"
Column | Type | Modifiers
------------+---------------+--------------------------------------------------
create_dt | integer |
select create_dt from inv;
create_dt
-----------
75864
74575
76842
76842
75227
75227
76700
CREATE OR REPLACE FUNCTION declarion(int) RETURNS date
AS $$ select (concat($1, ' days')::interval + date('1800-12-28'))::date; $$
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
select declarion(create_dt) as create_dt from inv;
create_dt
------------
2008-09-12
2005-03-03
2011-05-18
2011-05-18
2006-12-15
2006-12-15
2010-12-27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment