How to convert column type from varchar to date in PostgreSQL? How to convert column type from varchar to date in PostgreSQL? postgresql postgresql

How to convert column type from varchar to date in PostgreSQL?


ALTER TABLE <tablename> ALTER COLUMN <columnname> TYPE DATE using to_date(<columnname>, 'YYYY-MM-DD');


UPDATE tableName SET dateColumn=to_date(varcharColumn, 'DD MM YYYY')

Assuming you are saving "07 04 2010"

You can find further examples and explanation in the documentation:

http://www.postgresql.org/docs/current/interactive/functions-formatting.html


to_date('05 Dec 2000', 'DD Mon YYYY')