helloise Posted May 24, 2011 Share Posted May 24, 2011 in my MySql database i have a field "created_at" = now() for ex: 2011-05-23 11:47:28 i need to add two hours to that so i have 2011-05-23 13:47:28 how will i do this please? i have this so far but it is not correct: $currentTime = time($msg->getCreatedAt()); $timeAfterOneHour = $currentTime+60*60; $date=date("Y-m-d H:i:s",$timeAfterOneHour); please help thank you Quote Link to comment https://forums.phpfreaks.com/topic/237307-adding-2-hours-to-now/ Share on other sites More sharing options...
gristoi Posted May 24, 2011 Share Posted May 24, 2011 $date=date("Y-m-d H:i:s",time() + 7200); Quote Link to comment https://forums.phpfreaks.com/topic/237307-adding-2-hours-to-now/#findComment-1219482 Share on other sites More sharing options...
Fadion Posted May 24, 2011 Share Posted May 24, 2011 or $date = date('Y-m-d H:i:s', strtotime('+2 Hours')); Quote Link to comment https://forums.phpfreaks.com/topic/237307-adding-2-hours-to-now/#findComment-1219515 Share on other sites More sharing options...
Adam Posted May 24, 2011 Share Posted May 24, 2011 In what context are you needing this? MySQL has date functions built-in that would allow you to do what you want: DATE_ADD(`date_column`, INTERVAL 2 HOUR) Edit Or when used with a string: DATE_ADD('{$date_var}', INTERVAL 2 HOUR) Quote Link to comment https://forums.phpfreaks.com/topic/237307-adding-2-hours-to-now/#findComment-1219518 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.