Jump to content

Update date field


Suchy

Recommended Posts

Both of your formats are totally useless as db date columns.

 

Change to 2007-06-08 11:40:24 and change column type to DATETIME

 

Then you can compare dates, sort by dates, query by date or date ranges, use Mysql date/time functions

 

NOTE: I've assumed 06 is the month and 08 is the day as you don't specify and there is no location in your profile (if it's the other way round you'll have to adjust the fomat string below) You will also need to provide your tablename and date_column name in the queries.

 

Backup your table first (in case it doesn't work, although it did in my test)

 

To change the format

UPDATE tablename SET date_col = STR_TO_DATE(date_col, '%m, %d, %Y, %H:%i:%s')

 

then change col type

ALTER TABLE `tablename` MODIFY COLUMN `date_col` DATETIME;

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.