RE: [PHP-DB] Use date in For Loop
| From: | Greg Wiley | Date: | Thu, 01 May 2003 12:27:36 +0000 |
| Subject: | RE: [PHP-DB] Use date in For Loop | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27468@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ignatius Reilly wrote:
> 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.
>
True, that works with one less function call to make, but...
> The increment also works allright, albeit I do not know why (?)
>
This wouldn't work for $dt = "2003-04-26" and $to = "2003-05-05" for
example.
Converting to a timestamp you could increment by 86400 to get the
next day.
Cheers, Greg.
> 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
-----BEGIN PGP SIGNATURE-----
Version: PGP 7.0
Comment: http://www.thus.co.uk/pgpinfo for more
information
iQA/AwUBPrESuCcZ9eykZgHcEQJaqgCgljZbbJvOhBM/oPZFsfMsKC6NVyAAn03m
a6/5vsWwwB5e/pyEYxMKh/j/
=33WV
-----END PGP SIGNATURE-----