Re: strtotime() function as a do...while condition

From: Date: Mon, 11 Sep 2000 16:05:09 +0000
Subject: Re: strtotime() function as a do...while condition
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-2577@lists.php.net to get a copy of this message
Simon Cox wrote: > I am having a problem using the strtotime() function as a do...while > condition (see below). When ever I use the following code with the month of > October (any year), I generate a endless loop; all other months are fine. I > am using PHP 4.0.2 and Apache 1.3.12 under MS Windows 98 SE. > > Any ideas? Try reversing your logic a bit... instead of trying to do date operations on string objects, why not directly deal with full timestamps from the get-go? Here's a snip of code that should do what you want... <?php $dtDate = mktime(0,0,0,10,01,2000); $nMonth = "10"; do { // Build a calendar table echo date("m/d/y",$dtDate)."<br>\n"; $dtDate = $dtDate + 86400; } while (date("m", $dtDate) == $nMonth); ?> When doing date/time arithmetic, best to leave it always in a timestamp format, and ONLY convert to a string when displaying... instead of going back & forth from string-to timestamp-to string-to timestamp-etc., etc. -- Andy Hoffman Web Developer Bristol-Myers Squibb email: andy.hoffman@bms.com

« previous php.windows (#2577) next »