473,767 Members | 7,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

converting varchar date strings to date

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*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #1
3 7267
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_d ay)::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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2501
by: Erik R.N. | last post by:
Hi I have a ACCESS2002 table with a date-field in format "dd-mm-yyyy" which I "export" to a txt-file ( ; and " " ) and upload the txt-file to a MYSQL-table where the datefield is a varchar-field. I want to sort on the MYSQL-date-field. How do I get a MYSQL-date-formated "yyyy-mm-dd" field which I can sort on ??
3
118838
by: Nikola | last post by:
Hi all, I have a problem converting datetime to integer (and than back to datetime). Depending whether the time is AM or PM, same date is converted to two different integer representations, which holds as true on reversal back to datetime. AM Example:
3
23822
by: usenet | last post by:
I have inherited a table where date information was saved from PHP as a VARCHAR. (Sigh.) This means that the so-called date fields look like this : August 1, 2005, 9:09 am EDT October 13, 2004, 12:28 pm EDT This makes them essentially useless for sorting and logical evaluation. Understandbly, the MySQL date functions don't seem able to convert the field to a "real" date field. This yields a blank (or maybe null) "realdate" :
3
1244
by: pw | last post by:
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;
1
1952
by: ree32 | last post by:
I am having problems with Date Strings when using VS.net method of converting an XML document to a dataset. I need the the date nodes to be of date type. As I am loading the Dataset to a datagrid, and I using the sort facility to sort by date. Currently the dates are being treated as strings.
5
2396
by: MattEustace | last post by:
Hi, I have a varchar column with mixed date formats, some are dd-mm-yyyy and others are mmm dd yyyy hh:mmAP, these latter having been generated automatically by SQL when I changed the column datatype from datetime to varchar. I would like to run an update script to pattern match the latter and change to the former. I've been trying something along the lines of update dwsubmit set authoreddate = (select day(authoreddate))+'-'+(select...
3
3477
by: SparkByte | last post by:
Now I know this has been asked before, but I am not getting the same error as mentioned in the earlier posts I could find. Server is SQL 2000 Ent. As you can see the table is for parsing Security event logs. This information is then used to create reports that are sent out to clients. Problem: The Strings and message values from the EventLogs gets truncated when pulled from the servers. (68 of them) When I try to set the columns to...
3
7162
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying to autoformat the contents of text entries in a GUI. For numbers, I'm converting the text representation to the appropriate type (using atoi, atof, ...) and converting the result back to text with the correct format (using sprintf). But this does...
0
1742
Krishna Ladwa
by: Krishna Ladwa | last post by:
In Sql Server 2000 Version, I found that no Notification message box appears when converting text column to varchar but the data gets truncated to the given size for the varchar. Whereas it appears when you convert the varchar column to text column. Do this through Enterprise Manager Console Create a New table with a column as varchar datatype from Enterprise Manager  table created  Open the table and add one row  Successfully added the...
5
2067
by: =?Utf-8?B?emlubw==?= | last post by:
I need to convert a string as: "DEC 18 2007 2:49:40:783PM" to a date. This value is sent by SQL server as :select convert(varchar(30), creationDate, 109) from ... ... . I tried : Dim dt As DateTime Dim myCultureInfo As New CultureInfo("en-US") If DateTime.TryParseExact("Dec 18 2007 2:49:40:783PM", "mon dd yyyy hh:mi:ss:mmmAM", myCultureInfo, Globalization.DateTimeStyles.None, dt) Then .... ...
0
9575
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10014
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9960
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8840
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3534
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2808
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.