Re: [GENERAL] How to Convert VarChar to Date in PgSQL

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Venkat Rao Tammineni <vtammineni(at)roulacglobal(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-admin(at)postgresql(dot)org
Subject: Re: [GENERAL] How to Convert VarChar to Date in PgSQL
Date: 2009-03-10 12:09:20
Message-ID: 49B65870.60807@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

On 10/03/2009 12:07, Venkat Rao Tammineni wrote:
> I have one table which has lot of data.In the same table I have one
> varchar filed. I want to convert into Date data type? Is It possible to
> convert varchar to date datatype with out loosing data.Please guide me.I am
> waiting for your great response.

If the varchar is already in the format you need (yyyy-mm-dd) then you
ought to be able just to cast it:

'2009-03-10'::date

If not, you may need to do some clever things with regular expressions
first to get it into this format, and then cast it.

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Jaume Sabater 2009-03-10 12:11:27 Re: How to Convert VarChar to Date in PgSQL
Previous Message Venkat Rao Tammineni 2009-03-10 12:07:38 How to Convert VarChar to Date in PgSQL

Browse pgsql-general by date

  From Date Subject
Next Message Jaume Sabater 2009-03-10 12:11:27 Re: How to Convert VarChar to Date in PgSQL
Previous Message Venkat Rao Tammineni 2009-03-10 12:07:38 How to Convert VarChar to Date in PgSQL