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
https://forums.phpfreaks.com/topic/83448-update-date-field/#findComment-424593
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.