21. december 2001 - 15:58
#4
sorry:
// iso or non-iso week no.
$weektype = 1; // iso
// local formatting according to language/country
setlocale(\'LC_TIME\',\'danish\');
// test specific date yyyymmdd
$date = \"19990104\";
// functions
function week_number ( $date ) {
if ( $weektype == 1 )
return strftime ( \"%V\", $date ); // ISO Weeks -- which start on Mondays
else
return strftime ( \"%W\", $date );
}
// Get the Sunday of the week that the specified date is in.
// (If the date specified is a Sunday, then that date is returned.)
function get_sunday_before ( $year, $month, $day ) {
$weekday = date ( \"w\", mktime ( 2, 0, 0, $month, $day, $year ) );
$newdate = mktime ( 2, 0, 0, $month, $day - $weekday, $year );
return $newdate;
}
// Get the Monday of the week that the specified date is in.
// (If the date specified is a Monday, then that date is returned.)
function get_monday_before ( $year, $month, $day ) {
$weekday = date ( \"w\", mktime ( 2, 0, 0, $month, $day, $year ) );
if ( $weekday == 0 )
return mktime ( 2, 0, 0, $month, $day - 6, $year );
if ( $weekday == 1 )
return mktime ( 2, 0, 0, $month, $day, $year );
return mktime ( 2, 0, 0, $month, $day - ( $weekday - 1 ), $year );
}
// testscript
if ( ! empty ( $date ) && strlen ( $date ) > 0 ) {
$thisyear = $year = substr ( $date, 0, 4 );
$thismonth = $month = substr ( $date, 4, 2 );
$thisday = $day = substr ( $date, 6, 2 );
} else {
if ( empty ( $month ) || $month == 0 )
$thismonth = date(\"m\");
else
$thismonth = $month;
if ( empty ( $year ) || $year == 0 )
$thisyear = date(\"Y\");
else
$thisyear = $year;
if ( empty ( $day ) || $day == 0 )
$thisday = date(\"d\");
else
$thisday = $day;
}
if ( $weektype == 1 )
$wkstart = get_monday_before ( $thisyear, $thismonth, $thisday );
else
$wkstart = get_sunday_before ( $thisyear, $thismonth, $thisday );
// get current week no.
$ugenr = week_number($wkstart);