...

View Full Version : adding 2 hours to now()??



helloise
05-24-2011, 09:04 AM
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

kairog
05-24-2011, 09:25 AM
you can use this...

DATE_ADD(NOW(), INTERVAL 2 HOUR)

hope that helps

helloise
05-24-2011, 10:01 AM
is this php code?

er4o
05-24-2011, 10:22 AM
Try like this:


$currentTime = time($msg->getCreatedAt());
$timeAfterOneHour = $currentTime+(60*60*2);
$date=date("Y-m-d H:i:s",$timeAfterOneHour);

tangoforce
05-24-2011, 01:06 PM
You can also use date() with a relative time format (http://uk3.php.net/manual/en/datetime.formats.php).



$currentTime = time($msg->getCreatedAt());
$date=date("Y-m-d H:i:s", strtotime("+2 hours", $currentTime));



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum