Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a integer to date

Tags:

postgresql

I am having an issue with converting an integer date (20180525) to a date in the format of YYYY-MM-DD. Is there a way to do this or should I just convert it in code (Java in this case)? Any help with this would be most appreciated. Thank you!

like image 255
Joseph Freeman Avatar asked Jul 13 '26 06:07

Joseph Freeman


1 Answers

if your dates are stored as integers with YYYYMMDD, you can pass it to the date function by first casting to TEXT.

SELECT date(20180525::TEXT)

otherwise, use the function to_date with a date formatter:

SELECT to_date(20180525::text, 'YYYYMMDD')
like image 193
Haleemur Ali Avatar answered Jul 15 '26 22:07

Haleemur Ali