By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,710 Members | 1,970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,710 IT Pros & Developers. It's quick & easy.

converting varchar date strings to date

P: n/a
pw
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
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #2

P: n/a
pw writes:
How can I typecast a date generated from VARCHAR fields into
a date field


Using CAST().

--
Peter Eisentraut pe*****@gmx.net
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #3

P: n/a
pw
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

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


Using CAST().

--
Peter Eisentraut pe*****@gmx.net

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.