Last active
August 29, 2015 14:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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