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 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); 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')); 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) 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
Archived
This topic is now archived and is closed to further replies.