Re: Use date in For Loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:  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
>
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux