RE: Use date in For Loop

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

 



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





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