Jump to content

SQL Update


Samuz

Recommended Posts

I'm not sure if this is explicitly a MYSQL situation so please move the thread to that forum if it is.

 

Anyway I have a table which was storing dates in this format:

 

'3/31/2012 12:13:21 AM'

 

I can currently convert it so that it stores the data in a more british format, with no time values:

 

'31/03/2012'

 

My problem is I have about 100,000 rows of data in my table, all with the American format & timestamp.

 

Can anyone suggest how I will convert & update all those rows into the English format above?

 

I did abit of googling before hand and I came across some of the MYSQL functions, but i'm not too sure how i'd implement those in an update query?

 

I'd appreciate if anyone could share some advice please.

Link to comment
https://forums.phpfreaks.com/topic/265202-sql-update/
Share on other sites

You should be storing date or date/time values using mysql's native DATE or DATETIME data types, which have formats of YYYY-MM-DD or YYYY-MM-DD HH:MM:SS.

 

You can add a DATE data type column to your table and populate it using one UPDATE query that uses the mysql STR_TO_DATE() function to read the existing column values and produce mysql DATETIME value. Since your existing values have the time, you would also need to use the mysql DATE() function to only get the date part.

 

ref: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date

Link to comment
https://forums.phpfreaks.com/topic/265202-sql-update/#findComment-1359110
Share on other sites

You must have missed this -

You can add a DATE data type column to your table and populate it using one UPDATE query that uses the mysql STR_TO_DATE() function to read the existing column values and produce mysql DATETIME value. Since your existing values have the time, you would also need to use the mysql DATE() function to only get the date part.

 

ref: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date

Link to comment
https://forums.phpfreaks.com/topic/265202-sql-update/#findComment-1359112
Share on other sites

You must have missed this -

You can add a DATE data type column to your table and populate it using one UPDATE query that uses the mysql STR_TO_DATE() function to read the existing column values and produce mysql DATETIME value. Since your existing values have the time, you would also need to use the mysql DATE() function to only get the date part.

 

ref: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date

Ha sorry about that.

 

I'll have a go doing that.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/265202-sql-update/#findComment-1359113
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.