View Full Version : finding total weekends for the current year

10-27-2006, 11:47 AM
how can i get total weekends falling in the current year:confused:

Bhakti Thakkar

10-27-2006, 03:31 PM
The best I could come up with ...

But you need to really define what a weekend is.
Both Saturday and Sunday, or count one of those days as a weekend?

Same with days,
01/01/2006 --> 12/31/2006 or 01/01/2006 --> 01/01/2007
How you specify one year could end up adding 1 extra weekend.

It all depends on how you look at it.



$days_between=dateDiff("/", $date2, $date1);

echo "Days Between Dates: $days_between";
echo "<br><br>";
echo "Weekends: $weekends";

function dateDiff($dformat, $endDate, $beginDate)
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$ts1=mktime(0, 0, 0, $date_parts1[0], $date_parts1[1], $date_parts1[2]);
$ts2=mktime(0, 0, 0, $date_parts2[0], $date_parts2[1], $date_parts2[2]);
$difference = $ts2-$ts1;
$diffday = $difference/86400;
$startday=date(w,$ts1); //day of week
$endday=date(w,$ts2); //day of week

// do some calculations here on whether or not the first day is
// Sunday (therefore, considered a full weekend?
// You'll have to determine what you want to count as a weekend.
// (Sunday=0, Saturday=6)
// Same with the last day, what if Dec 31 is a Saturday?

return $diffday;