strtotime oddity

I was working out the best way to loop through a series of dates and tried this code. It gets stuck at Oct. 26, 2003 everytime. Can someone run this on their server and see if it does the same thing. I can find other ways to do this but I was confused why this wont work. Here’s the code.
[php]

<?php
$cur_date = '20030901';
$drop_date = '20040501';
$i = 0;

while ($cur_date <= $drop_date) {
	echo $cur_date."rn";
	echo strtotime($cur_date) + 86400;
	echo "rn";
	
	$cur_date = date('Ymd', strtotime($cur_date) + 86400);
	++$i;
	
	if ($i > 300) {
		exit('Caught loop');
	}
}
	
?>
[/php]

I am running this on a Linux server, slackware with 2.2.19 kernel, Apache 1.3.29 and PHP 4.3.6. Any input would be great. Like I said, I have a work around but it just caught me as odd. I was trying several ways to do this to see which was fastest and this one didn’t work.

Keith

You are making life more difficult for yourself by trying to use your own format for comparisons. If you are going to work with time, use timestamps:

<?php
$cur_date = '20040501';
$drop_date = '20040521';
$i = 0;
$current_date = strtotime($cur_date);
$drop_date = strtotime($drop_date);
while ($current_date <= $drop_date) {
	
    $current_date += 86400;
    ++$i;

    if ($i > 300) {
        exit('Caught loop');
    }
}
    
?> 

Thanks for not answering my question. Yeah, the final method I went with uses straight timestamps but why wont that method work? It doesn’t seem to want to add anymore onto the timestamp var after oct 26, 2004. It struck me as odd. I like to try a few different ways just to make sure I’m not missing a performance gain someplace. This is for an attendance module so it has to deal with thousands of kids attending class 5 days a week for a whole year. If a child’s enrollment info is modified I need to reverify every day that the child could possibly attend and make sure they are marked accordingly, along with all their meal info, djfs info, transporation info etc… This isn’t the method I went with, already said that, but I just wanted to see if someone knew why it worked like this.

Keith

Thanks for being an ass when I posted a solution that was more simple than the way you were doing it.

You are 100% welcome. Thanks again for posting a solution even though I didn’t ask for a solution and said that I already had a solution.

Keith

Still no reason to be an ass about it. I posted code to help you. So shut the hell up.

Sorry, this sort of behaviour does not put you in a good light with me, or any of the PHPHelp community users.

Topic locked, consider this a warning, if it happens again you will mysteriously vanish from our boards…

Sponsor our Newsletter | Privacy Policy | Terms of Service