MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 18th, 2013, 01:23 PM
chichai chichai is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 266 chichai User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 10 h 9 m 38 sec
Reputation Power: 10
Help with convert a string to date

2 years ago I was a very beginner learning with mysql and php and I created my first MySQL database and I made a huge mistake and now I am regret.

That mistake was I created a table that has a date column but I created that column as a Text data type and that column now has over 2000 records in format like this "01:13:2006" and the column name is regdate

Now, I am having problem with this date column and I would like to convert this column into a date datatype with its format like "01/13/2006"

I tried this statement
PHP Code:
 UPDATE mytable SET newdate =  STR_TO_DATE(oldate'%m/%d/%y'

but it does not do any update.

Can you help me?
Thanks

Reply With Quote
  #2  
Old February 18th, 2013, 02:36 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,375 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 28 m 13 sec
Reputation Power: 4140
Quote:
Originally Posted by chichai
...format like this "01:13:2006" and the column name is regdate
you were close
Code:
UPDATE mytable SET newdate =  STR_TO_DATE(regdate, '%m:%d:%Y')  
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old February 18th, 2013, 08:47 PM
chichai chichai is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 266 chichai User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 10 h 9 m 38 sec
Reputation Power: 10
Quote:
Originally Posted by r937
you were close
Code:
UPDATE mytable SET newdate =  STR_TO_DATE(regdate, '%m:%d:%Y')  


So I can't use this format %m/%d/%Y?

Could you please show me if after I converted to this format %m:%d:%Y then to this %m/%d/%Y?

Reply With Quote
  #4  
Old February 18th, 2013, 10:30 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,375 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 28 m 13 sec
Reputation Power: 4140
you need to understand the difference between a DATE datatype, and the string representation of a date

once you have created your DATE column values, you can display them in whatever format you want, using the DATE_FORMAT function if you want to do it in the sql

however, best practice says to retrieve the DATE untouched, and do any custom formatting in the application language (php or whatever)

Reply With Quote
  #5  
Old February 18th, 2013, 11:05 PM
chichai chichai is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 266 chichai User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 10 h 9 m 38 sec
Reputation Power: 10
Quote:
Originally Posted by r937
you need to understand the difference between a DATE datatype, and the string representation of a date

once you have created your DATE column values, you can display them in whatever format you want, using the DATE_FORMAT function if you want to do it in the sql

however, best practice says to retrieve the DATE untouched, and do any custom formatting in the application language (php or whatever)


Ah, got it.

Thanks so much

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Help with convert a string to date

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap