angst
11-12-2007, 07:51 PM
Hello,
I'm trying to make what i thought would be a simple function. but i'm a bit stuck at the moment.
I've found this code on php.net:
$year = date("Y", $date);
$month = date("m", $date);
if( (isset($_GET['year'])) && (intval($_GET['year']) > 1582) ){
$year = intval($_GET['year']);
}
if( (isset($_GET['month'])) && (intval($_GET['month']) >= 1) && (intval($_GET['month']) <= 12) ){
$month = intval($_GET['month']);
}
$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;
echo $weeks_of_month;
which will get the number of weeks in the current month.
but I'm having issues figuring out the best way to find the currently week of month. for example, right now it's November week 3.
again seems like this should be simple. but i'm just not seeing the logic yet.
cheers,
-Ken
I'm trying to make what i thought would be a simple function. but i'm a bit stuck at the moment.
I've found this code on php.net:
$year = date("Y", $date);
$month = date("m", $date);
if( (isset($_GET['year'])) && (intval($_GET['year']) > 1582) ){
$year = intval($_GET['year']);
}
if( (isset($_GET['month'])) && (intval($_GET['month']) >= 1) && (intval($_GET['month']) <= 12) ){
$month = intval($_GET['month']);
}
$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;
echo $weeks_of_month;
which will get the number of weeks in the current month.
but I'm having issues figuring out the best way to find the currently week of month. for example, right now it's November week 3.
again seems like this should be simple. but i'm just not seeing the logic yet.
cheers,
-Ken