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

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация