function whatsweek($anytime) {
//verify if $anytime is a valid unix time stamp (integer > 0)
$month = date('n', $anytime);
$year = date('Y', $anytime);
$first = mktime(1,1,1,$month,1,$year);
$starts = date('w', $first);// sunday = 0, ... sat = 6
$day = date('j', $anytime);
$firstweek = 7 - $starts;// number of days of the first week
$flag = FALSE;
$analiz_day = $firstweek;
$week = 1;
while ($flag = FALSE) {
if ($day <= $analiz_day) {
return($week);
$flag = TRUE;
} else {
$analiz_day += 7;
$week++;
}
}
}
$anytime is an integer with unix time stamp.
humm.. well, i wrote this at browser, never tested.. it surely contains sintaxe errors..
and i dont know if the while is the best way.. i used thousands of variables, if you are a purist, please dont go die reading this.. 🙂
but i think this is the idea..