#18655 [Opn->Bgs]: strtotime() with "next Sunday"
| From: | rasmus@php.net | Date: | Tue, 30 Jul 2002 18:11:58 +0000 |
| Subject: | #18655 [Opn->Bgs]: strtotime() with "next Sunday" | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-15613@lists.php.net to get a copy of this message | ||
ID: 18655
Updated by: rasmus@php.net
Reported By: thearcher@comcast.net
-Status: Open
+Status: Bogus
Bug Type: Date/time related
Operating System: RedHat 6.2 kernel 2.4.18 #3
PHP Version: 4.2.2
New Comment:
strtotime() will return the first sunday it finds after the given
timestamp in this case. So you really need to move the timestamp ahead
each time and ask it to find the next Sunday in order to prevent it
from finding the same Sunday again. Or perhaps keep adding 1 week
instead once you found the first one. Watch out for the daylight
savings switchover though.
Previous Comments:
------------------------------------------------------------------------
[2002-07-30 13:57:20] thearcher@comcast.net
The configure line is:
'./configure' '--enable-ftp' '--enable-bc-math'
'--enable-gd-native-ttf' '--enable-inline-optimization'
'--enable-mbstring' '--enable-mbstr-enc-trans' '--enable-sysvsem'
'--enable-sysvshm' '--enable-sockets' '--enable-track-vars'
'--enable-trans-sid' '--with-freetype-dir=/usr' '--with-gd=/usr'
'--with-imap=/usr' '--with-imlib=/usr' '--with-jpeg-dir=/usr'
'--with-kerberos=/usr/kerberos' '--with-mysql=/usr/local/mysql'
'--with-openssl=/usr' '--with-png-dir=/usr' '--with-t1lib=/usr'
'--with-ttf=/usr' '--with-xml' '--with-xpm-dir=/usr/X11R6'
'--with-zlib-dir=/usr' '--with-apache=../apache_1.3.26' '--with-snmp'
'--enable-ucd-snmp-hack'
I was writing a script that was supposed to determine all the Sundays
between an entered date and the current date. I had a loop in which I
used "strtotime("next Sunday",$date)". This did not work and just
returned the sunday after the current date instead of the Sunday after
the timestamp i gave it. I had used an identical expression outside of
the loop and it correctly returned the next Sunday of the timestamp i
gave it.
This script replicates the problem:
<?
$now=time();
$date=strtotime("November 24, 2002");
while($now<$date) {
echo date("l, F j, Y", $now)."<br>";
$now=strtotime("next Sunday", $now);
}
?>
That loop will never terminate as it logically should.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18655&edit=1