Cast a String to Timestamp in PostgreSQL
If storing a date/timestamp in a varchar or text field in postgres, the to_timestamp() function will let you access the value as a ‘real’ date. The second parameter tells the function the format of your string:
SELECT to_timestamp('2008-08-01', 'YYYY-MM-DD') AS date;
Tags: database, postgres, Programming, snippet
Just a note to anyone else sent here by Google… The code snippet is missing the underscore between “to” and “timestamp”.
Thanks, Chris!
Thanks Sam,
Looks like the code parser I used was stripping the underscore, so I’ve taken out the code highlighting to show the correct syntax.
Chris