Reply to Re: [PHP] Saturdays and Sundays

Your name:

Reply:


Posted by Philip Hallstrom on 10/10/81 11:26

> Is it possible to get the number of saturdays and sundays for a given month
> / year?

This seems to work...


<?php

$month = 9;
$year = 2005;
$day = 1;

$ts = mktime(0, 0, 0, $month, $day, $year);

$week_day = date("w", $ts); // 0 (for Sunday) through 6 (for Saturday)

if ( $week_day > 0 && $week_day < 6 ) {
$day += 6 - $week_day; // $day = first saturday
}

$ts = mktime(0, 0, 0, $month, $day, $year);
$tmp_month = date("n", $ts); // 1 - 12

while ( $month == $tmp_month ) {
$num_satsuns += 2;
$day += 7;

$ts = mktime(0, 0, 0, $month, $day, $year);
$tmp_month = date("n", $ts); // 1 - 12
}

print("Number of Sat/Suns: $num_satsuns\n");

?>

[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

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