Re: converting varchar date strings to date

From: Richard Huxton <dev(at)archonet(dot)com>
To: "pw" <p(dot)willis(at)telus(dot)net>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: converting varchar date strings to date
Date: 2003-10-14 17:30:11
Message-ID: 200310141830.11117.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tuesday 14 October 2003 17:54, pw wrote:
> Hello,
>
> How can I typecast a date generated from VARCHAR fields into
> a date field
>
> ie:
>
> UPDATE inventory SET date_field = vc_year||'-'||vc_month||'-'||vc_day;

... SET date_field = CAST(vc_year...vc_day AS date)
or
... SET date_field = (vc_year...vc_day)::date

The first is SQL-standard, the second less typing.

If that gives you problems, cast to text first, then to date.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2003-10-14 17:39:17 Re: How to list which tables are available?
Previous Message Richard Huxton 2003-10-14 17:28:19 Re: How to list which tables are available?