×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Database (MySQL)

How do I convert dd/mm/yy to YYYY-MM-DD by KarveR
Posted: 31 Dec 03

DISCLAIMER:
Aways backup your data prior to running any code listed below. Rule number one applies. You break it , YOU have to fix it. Caution is a good thing, and I'm miles away
---------------------------------------------------------------------------

You have a date field in your existing db and you wish to use the dates from it in MySQL in a field of type DATE. You will need to reformat the dates.

1) Ensure you have 2 date fields in your new table; one of type DATE (new_date) and an additional field VARCHAR(10) (old_date) into which you insert your original records.

2) Run the following update on the table:
UPDATE my_table SET new_date=date_format(concat(@year:=substring(old_date ,7,2),@month:=substring(old_date ,4,2),@day:=substring(old_date ,1,2)), '%Y-%m-%d');  

*note:
 This is for dd/mm/yy but you can move the elements around in the UPDATE query.

 This query will run on just one field if required, just set the source and target field names the same (make sure the type of field is correct first).


Back to PHP FAQ Index
Back to PHP Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close