Page 1 of 1

Changing server time

Posted: Wed Oct 19, 2005 5:13 pm
by blinddrop
Hi, I've studied the date() function page on php.net, and searched for a solution, but to no avail, although I reckon there's an easy answer to this question:

How do I subtract 2 hours from the following date timestamp?

$day = date("d ");
$year = date(" Y, H:i:s");


return $month.$day.$year;

The MySQL field is set to a timestamp of NOW(). The server is running PHP4.x so the new PHP 5 function for setting a certain timezone is not possible.

Thanks in advance!

Posted: Wed Oct 19, 2005 5:20 pm
by pickle
I ran through the halls shouting for joy when I found strtotime(). You can use it like so:

Code: Select all

$timestamp = time();
$less_2_hours = strtotime('-2 hours',$timestamp);

Posted: Wed Oct 19, 2005 9:12 pm
by Jenk
Or just

Code: Select all

$timestamp = time();
$less_two_hours = $timestamp - 6400;

Posted: Thu Oct 20, 2005 1:50 pm
by pickle
Jenk wrote:Or just

Code: Select all

$timestamp = time();
$less_two_hours = $timestamp - 6400;
Unless those two hours span a transfer between standard and daylight saving time ;) That's what makes strtotime() so nice - it takes that into consideration.