Re: Looking for a date function : "First Monday after a certain date"
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Looking for a date function : "First Monday after a certain date"

From: Emmanuel Ayrault <emmanuel.ayrault@nospamvoila.fr>
Date: Sun Jul 31 2005 - 00:47:08 CEST

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
Received on Tue Oct 18 02:06:30 2005