Page 1 of 1

Strange date behaviour - plz help

Posted: Thu May 11, 2006 2:29 am
by richza
I use the following variables as my date ranges in a reporting tool:

$this_week = date("Y-m-d H:m:s", strtotime("2006-01-01 00:00:00"));
$next_week = date("Y-m-d H:m:s", strtotime("$this_week + 1 week"));
$prev_week = date("Y-m-d H:m:s", strtotime("$this_week - 1 week"));

On my test server on my windows pc they return the correct dates, but on my linux server $next_week and $prev_week come out the same.
My test server is running PHP 5 and the web server is running PHP 4.
So I am not sure whether its the version difference or the platform difference.

Any ideas?

Thanks,
Rich

Posted: Thu May 11, 2006 2:39 am
by Maugrim_The_Reaper
Your last two lines are the exact same calculation - they both should be identical even on Windows...

Posted: Thu May 11, 2006 3:05 am
by richza
Sorry that was a forum typo, the actual script is correct, have edited the post.

K, now anyone know whats wrong?

Posted: Thu May 11, 2006 10:51 am
by aerodromoi
richza wrote:Sorry that was a forum typo, the actual script is correct, have edited the post.

K, now anyone know whats wrong?
Looks like PHP 5 vs. PHP 4
In PHP 5 up to 5.0.2, "now" and other relative times are wrongly computed from today's midnight. It differs from other versions where it is correctly computed from current time.
http://de3.php.net/strtotime

aerodromoi

Posted: Thu May 11, 2006 11:42 am
by Burrito
I have seen cases where the minus operator (-) and spaces screws things up with strtotime().

you might try removing your space between - 1 (make it -1).