Reply to Re: Saturdays and Sundays

Your name:

Reply:


Posted by "M. Sokolewicz" on 10/11/66 11:26

since only the total number of saturdays/sundays is what he wants to
know, you can use some clever math. Basically, the amount of saturdays
in a year is:
floor(365 (+1 if it's a leap year) (-days from january first to first
saturday) / 7);
and sundays = saturdays (-1 if the modulo from the top one is 0)

I can't quickly come up with a way to find out what day in the first
month would be a saturday... but if you know that, then this should work
for you

Wong HoWang wrote:
> the answer is simply yes!
> You can have a simple for looping to do so.
>
> <?php
> // for example, 02/2005
> $year = 2005;
> $month = 02;
>
> for ($i = 1; $i <= 31 ; $i++) {
> if (checkdate($month,$i,$year)) {
> if (date("w",mktime(0,0,0,$month,$i,$year)) == '0') // it is Sunday
> echo $i . '/' . $month . '/' . $year . "\n";
> if (date("w",mktime(0,0,0,$month,$i,$year)) == '6') // it is Saturday
> echo $i . '/' . $month . '/' . $year . "\n";
> }
> }
> /** Sample output:
> 5/2/2005
> 6/2/2005
> 12/2/2005
> 13/2/2005
> 19/2/2005
> 20/2/2005
> 26/2/2005
> 27/2/2005
> **/
> ?>
>
> hope this help!
>
>
> ""Shaun"" <shaunthornburgh@hotmail.com>
> wrote:05.80.15098.C4FC6134@pb1.pair.com...
>
>>Hi,
>>
>>Is it possible to get the number of saturdays and sundays for a given
>>month / year?
>>
>>Thanks for your help.

[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

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