|
Posted by Emmanuel Ayrault on 07/31/05 01:47
Martien van Wanrooij a écrit :
> I would like to retrieve, let us say, the First Monday after a certain date,
> so my (imaginary) function
> could be something like
> echo weekdayAfter("28 July 2005", "Monday") should return "1 August 2005",
> (or a timestamp that could be formatted).
> I have been thinking about creating a loop that increases the source date
> $myDate with 24*60*60 until date("l", $myDate) = "Monday" but maybe I am
> trying too complicated solutions and overseeing more easy ones.
> Any suggestions?
>
> Martien van Wanrooij
>
>
Maybe, you should try this (I'm not sure)
Of course, it's necessary to test the input values of the function.
<?
function weekdayAfter($date,$day){
return date('d M Y',strtotime($day, strtotime($date)));
}
echo 'First Monday after 28 July 2005 is ';
echo weekdayAfter("28 July 2005", "Monday");
?>
It seems to work except if you are on Monday (in fact, it depends on
what you want to do). In this case, you have to use "next Monday" with
strtotime function.
Take a look at the strtotime function: http://www.php.net/function.strtotime
--
Manu
[Back to original message]
|