If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Convert varchar to date

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-09, 17:56
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Wink Convert varchar to date

In an inherited database I have a column of dates in varchar (5) i.e. 3/09 which I would like to convert to a date field. i.e 03/00/2009!
Reply With Quote
  #2 (permalink)  
Old 02-09-09, 18:05
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
03/00/2009 is not a valid date...
3rd Jan 09?
1st Mar 09?
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 02-09-09, 19:24
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
How about 2009-02-04 18:57:40 a standard formated mysql date?
Reply With Quote
  #4 (permalink)  
Old 02-09-09, 22:47
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by oldnickj
In an inherited database I have a column of dates in varchar (5) i.e. 3/09 which I would like to convert to a date field. i.e 03/00/2009!
your best bet is to chose the 1st of the month

e.g.
3/09 --> 2009-03-01
9/09 --> 2009-09-01
12/09 --> 2009-12-01

if this works for you, then use DATE(CONCAT('20',RIGHT(yourfld,2),'-',SUBSTRING_INDEX(yourfld,'/',1),'-01'))

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-11-09, 01:39
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Cool I'll try it!

Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On