mrjameer Posted May 2, 2007 Share Posted May 2, 2007 hi, i have a table in which there are 2 fields 1.id 2.date. values 1 2005-07-28 15:07:52 the time is 3:07:52. here what i want to do is i want to add 8 hours to the above time (result should be like 2005-07-28 11:07:52 PM).if it exceeds the date just take next day's date.any of your help will be surely appreciated. thanks mrjameer Quote Link to comment Share on other sites More sharing options...
esukf Posted May 2, 2007 Share Posted May 2, 2007 <?php $date = "2005-07-28 15:07:52"; echo date("Y-m-d h:i:s A", strtotime("$date + 8 hours")); ?> Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted May 2, 2007 Share Posted May 2, 2007 Follow this link: http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-add Then scroll down until you see: As of MySQL 3.23, date arithmetic also can be performed using INTERVAL together with the + or - operator: date + INTERVAL expr unit date - INTERVAL expr unit Following is a list of date manipulations you can perform right in SQL without using any PHP code. Quote Link to comment Share on other sites More sharing options...
mrjameer Posted May 2, 2007 Author Share Posted May 2, 2007 hi thanks for your response.esukf your code works fantastic..this is what i exactly want. thanks to all guys for the reply's mrjameer Quote Link to comment Share on other sites More sharing options...
obsidian Posted May 2, 2007 Share Posted May 2, 2007 here what i want to do is i want to add 8 hours to the above time (result should be like 2005-07-28 11:07:52 PM).if it exceeds the date just take next day's date.any of your help will be surely appreciated. Or, an example of how to let MySQL do the work for you (you will have to do this if your date falls outside of the UNIX timestamp range): SELECT DATE(date + INTERVAL 8 HOUR) FROM myTable; Quote Link to comment 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.