kumarrana Posted August 7, 2008 Share Posted August 7, 2008 It is kidda stupid to ask. I used a hard coded time format "July 04, 2007" stored on MySQL. Now I want to display a message a week from that date. Anybody know any easy solution. Quote Link to comment https://forums.phpfreaks.com/topic/118697-date-comarision/ Share on other sites More sharing options...
DarkWater Posted August 7, 2008 Share Posted August 7, 2008 Yeah, don't hardcode dates into MySQL. Change it to a DATE column and write a PHP script that loops through every row and fixes them. >_> Quote Link to comment https://forums.phpfreaks.com/topic/118697-date-comarision/#findComment-611136 Share on other sites More sharing options...
Barand Posted August 7, 2008 Share Posted August 7, 2008 This will convert your string to a mysql DATE type and add seven days. $sql = "SELECT STR_TO DATE(datecol, '%M $d, %Y') + INTERVAL 7 DAY"; But as DW said, better to change to mysql DATE type (format YYYY-MM-DD) as most other formats, such as yours, are of zero use as DB dates. You can use that same STR_TO DATE function to update your table. Quote Link to comment https://forums.phpfreaks.com/topic/118697-date-comarision/#findComment-611175 Share on other sites More sharing options...
kumarrana Posted August 8, 2008 Author Share Posted August 8, 2008 Thanks, Darak and Dw for the idea. Quote Link to comment https://forums.phpfreaks.com/topic/118697-date-comarision/#findComment-611211 Share on other sites More sharing options...
PFMaBiSmAd Posted August 10, 2008 Share Posted August 10, 2008 It is not necessary to use any php code to fix date columns. 1) Backup your database. 2) Alter your table to add a new column of the correct type. 3) Run an UPDATE query (using the mysql STR_TO DATE() function) to populate the new column with the equivalent values from the existing column. 4) Modify and test your code to correctly use the new column. 5) Remove the old column. Quote Link to comment https://forums.phpfreaks.com/topic/118697-date-comarision/#findComment-612690 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.