Re: Use date in For Loop
| From: | Ignatius Reilly | Date: | Thu, 01 May 2003 12:07:24 +0000 |
| Subject: | Re: Use date in For Loop | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27467@lists.php.net to get a copy of this message | ||
I don't understand the design of your loop.
I tried the following:
$dt = '2003-04-22' ;
$to = '2003-04-30';
for ( $x = $dt; $x < $to ; ++$x )
{
print $x."<br/>" ;
}
which returns:
2003-04-22
2003-04-23
2003-04-24
2003-04-25
2003-04-26
2003-04-27
2003-04-28
2003-04-29
The comparison works allright because it will compare $dt and $to as strings
in the lexicographic order, whereby dates in the YYY-MM-DD compare
correctly.
The increment also works allright, albeit I do not know why (?)
HTH
Ignatius
____________________________________________
----- Original Message -----
From: "Greg Wiley" <greg@wileysworld.org>
To: "'Ramesh PAtel '" <ramesh@banas.guj.nic.in>;
<php-db@lists.php.net>
Sent: Thursday, May 01, 2003 1:40 PM
Subject: RE: [PHP-DB] Use date in For Loop
> Ramesh PAtel wrote:
> > Hi All
> >
> > please give one help
> >
> > I want to us date variable in for loop Condition.
> >
> > But it not working Properly.
> > $dt='2003-04-22' ;
> > $to='2003-04-30';
> >
> > FOR ( $dt=$dt; $dt > $to ; )
> > {
> > print "XYz";
> > }
> >
> You can't do this. What you need to do is convert your date into a
timestamp
> using mktime() and then do the comparison.
>
> Cheers, Greg.
>
>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>