Bug in php 5.0.3?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Bug in php 5.0.3?

Post by tores »

Hi

Try out this code...

Code: Select all

echo date('d F Y', strtotime('next monday', strtotime('15 July 2005')));
15th of July is on a Friday. Next monday is then 18th of July. However, when I run this code, 25th of July is returned... Is there a known bug in strtotime() for php ver. 5.0.3 that causes this?

regards tores
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If tried for 'monday' and this gave me 18 July 2005

Code: Select all

echo date('d F Y', strtotime('monday', strtotime('15 July 2005')));
So, from that result, it appears logical that 'next monday' is 25 July 2005

Code: Select all

echo date('d F Y', strtotime('last monday', strtotime('15 July 2005')));
echo "<br>";
echo date('d F Y', strtotime('monday', strtotime('15 July 2005')));
echo "<br>";
echo date('d F Y', strtotime('next monday', strtotime('15 July 2005')));
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post by tores »

Relative dates for dummies:)

Code: Select all

echo date('d F Y', strtotime('last monday', strtotime('15 July 2005'))); // 11th
echo "<br>";
echo date('d F Y', strtotime('this monday', strtotime('15 July 2005'))); // 18th
echo "<br>";
echo date('d F Y', strtotime('next monday', strtotime('15 July 2005'))); // 25th
Post Reply