converting varchar date strings to date

Started by pwover 22 years ago4 messagesgeneral
Jump to latest
#1pw
p.willis@telus.net

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;

where the date string is built up from varchar fields?

Thanks for any help.

Peter

#2Richard Huxton
dev@archonet.com
In reply to: pw (#1)
Re: converting varchar date strings to date

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

#3Peter Eisentraut
peter_e@gmx.net
In reply to: pw (#1)
Re: converting varchar date strings to date

pw writes:

How can I typecast a date generated from VARCHAR fields into
a date field

Using CAST().

--
Peter Eisentraut peter_e@gmx.net

#4pw
p.willis@telus.net
In reply to: Peter Eisentraut (#3)
Re: converting varchar date strings to date

Hello,

This has been resolved.
As I told a previous poster, CAST() wasn't working.
I have no idea why.

I finally used:

UPDATE inventory SET date_field=date(vc_year||'-'||vc_month||'-'||vc_day );

Peter

Show quoted text

pw writes:

How can I typecast a date generated from VARCHAR fields into
a date field

Using CAST().

--
Peter Eisentraut peter_e@gmx.net