$date = mktime(1, 1, 1, $month, date("d"), $year);
	$first_day_of_month = strtotime("-" . (date("d", $date)-1) . " days", $date);
	$last_day_of_month = strtotime("+" . (date("t", $first_day_of_month)-1) . " days", $first_day_of_month);
	$first_week_no = date("W", $first_day_of_month);
	$last_week_no = date("W", $last_day_of_month);
	if($last_week_no < $first_week_no) $last_week_no=date("W", strtotime("-1 week",$last_week_no)) + 1;
		$weeks_of_month = $last_week_no - $first_week_no + 1;
	return $weeks_of_month;

This is the code i m using but it wont works.this code is written by my senior and there is nobody to help me. If possible can someone help me to understand this?

8 Years
Discussion Span
Last Post by emixfr

Hey dude, If you want to find the number of weeks in a year and number of weeks in a month, just use the following code..

echo date("W", mktime(0,0,0,12,31,2010)); // To find number of weeks in a year

echo "<br />";

echo date("w", mktime(0,0,0,12,31,2010)); // To find number of weeks in a month

echo "<br />";


You're wrong on one thing, according to ISO documentation the good answer is :

echo date("W", mktime(0,0,0,12,28,$year)); // 28 december is always in the last week because weeks are 7 days

your code :

echo date("W", mktime(0,0,0,12,31,$year));

will return 01 for some years because the 31 december is in the first week of the next year

if you wan't more informations about that : http://en.wikipedia.org/wiki/ISO_week_date

Edited by emixfr: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.