I have stored dates on my mysql. Example 07-20-08 02:54:03 AM I want to shift date for 2 hours so it will automaticly be 07-20-08 04:54:03 AM How can i convert that time to 2 hours later. I tried too many things like date("m-d-y h:i:s A", strtotime("+2 hours",$date)); PHP: etc but i couldn't succeed it .
there is an addtime function for mysql havent tried this myself SELECT ADDTIME(yourdatefield, '02:00:00')
<? $date = "07-20-08 02:54:03 AM"; echo date("m-d-y h:i:s A", strtotime($date) + (2*60*60)); //output 01-01-70 04:00:00 AM ?> PHP: Now we are in year 2070
have you tried the solution i posted? i havent tested it myself, would love to know if it indeed work
<? $date = "07-20-08 02:54:03 AM"; echo date("m-d-y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y"))); ?> PHP: I have also a $date variable this must be on that $date
<?php $oldDate = '02/20/2008'; $newDate = new DateTime($oldDate); $newDate->modify('+2 Days'); echo $newDate->format('m-d-Y h:i:s a'); PHP:
here you go this is the easy way $date = "07-20-08 02:54:03 AM"; echo date("m-d-y h:i:s A", strtotime ("+2 hour")); PHP:
the problem is that strtotime doesn't understand the $date you give it. see http://ca3.php.net/manual/en/function.strtotime.php for details. use the timestamp instead of the formated date if you can, that will make it really easier to process.