20 August 2008 · About 1 minute read

PostgreSQL: 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:

sqlSELECT to_timestamp('2008-08-01', 'YYYY-MM-DD') AS date;

Chris Blunt
Chris Blunt @cblunt
Chris is the founder of Plymouth Software. As well as code and business, he enjoys being a Dad, swimming, and the fine art of drinking tea.