Page 1 of 1
Best way to subtract 2 hours from datetime expresion?
Posted: Wed Jan 27, 2010 8:28 pm
by gertrudis
Hi to all, I need to know how to subtract hour from date expression
command?
example: I want to sutract 2 hour to a time?
$acttime =date("H

s")-2;
thanks in advance!
Re: Best way to subtract 2 hours from datetime expresion?
Posted: Wed Jan 27, 2010 8:38 pm
by AbraCadaver
Code: Select all
$acttime = date("H:i:s", strtotime("-2 hours"));
Re: Best way to subtract 2 hours from datetime expresion?
Posted: Thu Jan 28, 2010 8:02 am
by gertrudis
Thanks a lot
Re: Best way to subtract 2 hours from datetime expresion?
Posted: Thu Jan 28, 2010 9:16 am
by AbraCadaver
Well I guess if you already have a timestamp, this works as well:
Code: Select all
$acttime = date("H:i:s", time()-7200); //subtract 7200 seconds
Re: Best way to subtract 2 hours from datetime expresion?
Posted: Thu Jan 28, 2010 2:34 pm
by akuji36
Use php offset
Ex
Code: Select all
<?php echo date("l"); ?>  
<?php echo date("F j, Y"); ?>  
<?php
$offset = strtotime("-5 hours");
echo date("h:i a", $offset);
?>
Using phpdate function and php offset.
This example gives the current time (eastern time)
- 5 hours. My server is five hours ahead. In order to return
eastern standard time I use this function.
thanks
Rod
Re: Best way to subtract 2 hours from datetime expresion?
Posted: Thu Jan 28, 2010 5:24 pm
by AbraCadaver
Redundant much?
Re: Best way to subtract 2 hours from datetime expresion?
Posted: Fri Jan 29, 2010 11:16 am
by pickle
AbraCadaver wrote:Well I guess if you already have a timestamp, this works as well:
Code: Select all
$acttime = date("H:i:s", time()-7200); //subtract 7200 seconds
Stick with strtotime(), that could cause problems during a Standard Time / Daylight Saving Time crossover.
Re: Best way to subtract 2 hours from datetime expresion?
Posted: Fri Jan 29, 2010 11:54 am
by AbraCadaver
pickle wrote:AbraCadaver wrote:Well I guess if you already have a timestamp, this works as well:
Code: Select all
$acttime = date("H:i:s", time()-7200); //subtract 7200 seconds
Stick with strtotime(), that could cause problems during a Standard Time / Daylight Saving Time crossover.
Good thought.