Reputation: 839
I want to convert date to specific format and subtract 2 hours from the time:
date
2018-06-07 23:37:10
Expected output:
07Jun2018 21:37:10
I have tried it, but I got the below error:
error:operator doesnt exist : Text -interval,might need to add explicit type cast.
Upvotes: 0
Views: 130
Reputation: 2859
You can try using TO_CHAR()
like this:
SELECT TO_CHAR('2018-06-07 23:37:10'::TIMESTAMP - INTERVAL '2 HOURS', 'DDMonYYYY HH24:MI:SS')
(changed to HH24:MI as Oto Shavadze suggested)
Here is the reference how to create patterns in case you need it in the future
Just remember that after the conversion the type of the value will be text
so you won't be able to perform any other date-related functions (you have to do it before TO_CHAR()).
Upvotes: 5