Strange date behaviour - plz help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
richza
Forum Newbie
Posts: 2
Joined: Thu May 11, 2006 1:42 am

Strange date behaviour - plz help

Post 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
Last edited by richza on Thu May 11, 2006 3:03 am, edited 1 time in total.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Your last two lines are the exact same calculation - they both should be identical even on Windows...
richza
Forum Newbie
Posts: 2
Joined: Thu May 11, 2006 1:42 am

Post by richza »

Sorry that was a forum typo, the actual script is correct, have edited the post.

K, now anyone know whats wrong?
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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).
Post Reply