Jump to content

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

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.