eva0212
Programmer
- Jun 30, 2008
- 8
Well... how to get number of weeks for a month that for a selected year? is does anybody know how to do this?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
function numWeeks($year, $month, $start=0){
$unix = strtotime("$year-$month-01");
$numDays = date('t', $unix);
if ($start===0){
$dayOne = date('w', $unix); // sunday based week 0-6
} else {
$dayOne = date('N', $unix); //monday based week 1-7
$dayOne--; //convert for 0 based weeks
}
//if day one is not the start of the week then advance to start
$numWeeks = floor(($numDays - (6 - $dayOne))/7);
return $numWeeks;
}
$Total1=max(date('W', mktime(0,0,0,1,25,$year)), date('W', mktime(0,0,0,1,31,$year)));
$Total2=max(date('W', mktime(0,0,0,2,25,$year)), date('W', mktime(0,0,0,2,31,$year)));
$Total3=max(date('W', mktime(0,0,0,3,25,$year)), date('W', mktime(0,0,0,3,31,$year)));
$Total4=max(date('W', mktime(0,0,0,4,25,$year)), date('W', mktime(0,0,0,4,31,$year)));
$Total5=max(date('W', mktime(0,0,0,5,25,$year)), date('W', mktime(0,0,0,5,31,$year)));
$Total6=max(date('W', mktime(0,0,0,6,25,$year)), date('W', mktime(0,0,0,6,31,$year)));
$Total7=max(date('W', mktime(0,0,0,7,25,$year)), date('W', mktime(0,0,0,7,31,$year)));
$Total8=max(date('W', mktime(0,0,0,8,25,$year)), date('W', mktime(0,0,0,8,31,$year)));
$Total9=max(date('W', mktime(0,0,0,9,25,$year)), date('W', mktime(0,0,0,9,31,$year)));
$Total10=max(date('W', mktime(0,0,0,10,25,$year)), date('W', mktime(0,0,0,10,31,$year)));
$Total11=max(date('W', mktime(0,0,0,11,25,$year)), date('W', mktime(0,0,0,11,31,$year)));
$Total12=max(date('W', mktime(0,0,0,12,25,$year)), date('W', mktime(0,0,0,12,31,$year)));
$TotalWeekJan=$Total1;
$TotalWeekFeb=$Total2-$Total1;
$TotalWeekMar=$Total3-$Total2;
$TotalWeekApr=$Total4-$Total3;
$TotalWeekMay=$Total5-$Total4;
$TotalWeekJun=$Total6-$Total5;
$TotalWeekJul=$Total7-$Total6;
$TotalWeekAug=$Total8-$Total7;
$TotalWeekSep=$Total9-$Total8;
$TotalWeekOct=$Total10-$Total9;
$TotalWeekNov=$Total11-$Total10;
$TotalWeekDec=$Total12-$Total11;
Assuming a Gregorian calendar, there are always 365 or 366 days in a year. Therefore, the total number of weeks in a year is either 52.143 (365 / 7) or 52.286 (366 / 7). I suggest you read the following sources:eva0212 said:Actually i want to get total week for a year first.
For example, "4 weeks" rather than "4.43 weeks"jpadie said:do you mean 'number of whole weeks'?
Sunday/Monday/other?jpadie said:starting on what day?