Forum Moderators: coopster

Message Too Old, No Replies

PHP Date() skips time

A calendar problem

         

rastamanxx

3:52 pm on Oct 20, 2008 (gmt 0)

10+ Year Member



Hello, i've been trying to make an output for a calendar, which will show from the selected day to 31 days ahead from that day. I can go forward or go back by 1 day, passing the 'day' parameter as 1 or -1. But something weird happens when i go from 2008-10-13 to 2008-10-12

This is an example:

$date = '2008-10-13';
$date = strtotime($date);
echo $date."-".date('Y-m-d H:i:s',$date)."<br>";
$date = $date + (-1 * 60*60*24);
echo $date."-".date('Y-m-d H:i:s',$date)."<br>";

Output:

1223863200-2008-10-13 00:00:00
1223776800-2008-10-11 23:00:00

It goes from 13 to 11?!
I've been testing with different values and it seems that it doesn't count from 2008-10-12 00:00:00 to 2008-10-12 01:00:00. Why does it happen?

Thanks in advance!

Anyango

3:59 pm on Oct 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



which PHP version are you using, seems like any timezone issue. It works fine on my server, here is the output

1223856000-2008-10-13 00:00:00
1223769600-2008-10-12 00:00:00

PHP 5.2.6

rastamanxx

4:15 pm on Oct 20, 2008 (gmt 0)

10+ Year Member



I'm using the same version, but it's running under EasyPHP (which also has Apache v. 2.23)

Anyango

6:54 pm on Oct 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What about

<?
$firstDate='2008-10-13';
$firstDateTS=strtotime($firstDate);
$secondDateTS=strtotime("$firstDate -1 day");

echo $firstDateTS."-".date('Y-m-d H:i:s',$firstDateTS)."<br>";
echo $secondDateTS."-".date('Y-m-d H:i:s',$secondDateTS)."<br>";
?>

Btw, TS=timestamp

[edited by: Anyango at 6:55 pm (utc) on Oct. 20, 2008]

rastamanxx

11:35 am on Oct 21, 2008 (gmt 0)

10+ Year Member



I tried that and it didn't work. Anyways, i uploaded it to the server and it worked fine. It might be a matter of EasyPHP.

Thanks Anyango!