Convert Bigint to Date in PostgreSQL -
hi have bigint column value ex : 20140130. need converted date column 2014/01/30 format yyyy/mm/dd using postgresql
please tell how can done ?
convert value string , use to_date() function:
select to_date(20140130::text, 'yyyymmdd'); more details to_date() function in manual:
http://www.postgresql.org/docs/current/static/functions-formatting.html
more information casting values in manual:
http://www.postgresql.org/docs/current/static/sql-expressions.html#sql-syntax-type-casts
converted date column ... format yyyy/mm/dd
a date column not have "a format". format see being applied date (or timestamp) column done client application (e.g. psql or other sql client).
the result of to_date() function date can formatted display using to_char()` function.
select to_char(to_date(20140130::text, 'yyyymmdd'), 'dd.mm.yyyy'); select to_char(to_date(20140130::text, 'yyyymmdd'), 'yyyy/mm/dd'); but formatting dates better left frontend , should not done in sql.
you should seriously consider fix table design , use proper date date column rather "encoded" bigint value.
Comments
Post a Comment