Datum Kalenderwoche (KW)
Mela
- php
0 bjb0 Sebastian Becker
Hi Folks,
ich suche für PHP folgende Funktion.
Welche Kalenderwoche gehört zu einem bestimmten Datum.
z.B.
$datum = 06.06.2003;
$kw = ???
Hat jemand eine fertige Funktion oder eine gute Beschreibung.
Gruß
Melanie
Hi Folks,
ich suche für PHP folgende Funktion.
Welche Kalenderwoche gehört zu einem bestimmten Datum.z.B.
$datum = 06.06.2003;
$kw = ???Hat jemand eine fertige Funktion oder eine gute Beschreibung.
Gruß
Melanie
erstmal ineine timestamp umwandeln und den dann mit date() zur woche umwandeln
$timestamp= mktime(0,0,0,6,6,2003); <-- geht bestimmt auch automatisch
$kw= date(W,$timestamp);
gruß
bjb
Hi, Melanie,
für die Wochennummer gibt es den ISO-Standard 8601. Dazu habe ich mal folgende Funktion gefunden (aber nicht getestet) ...
http://px.sklar.com/code.html?id=28
Grüße,
Sebastian
<?php
/* weeknumber.php
(int) get_week_number($timestamp)
Week number of year with Monday as first day of the week
(1...53). If the week containing January 1 has four or more days
in the new year, then it is considered week 1; otherwise, it is
week 53 of the previous year, and the next week is week 1.
(See the ISO 8601: 1988 standard.)
Adapted from GNU sh-utils for PHP3 by Stefan Rohrich, sr@linux.de,
http://home.pages.de/~sr/.
*/
function is_leap_year($year) {
if ((($year % 4) == 0 and ($year % 100)!=0) or ($year % 400)==0) {
return 1;
} else {
return 0;
}
}
/*
#define ISO_WEEK_START_WDAY 1 // Monday
#define ISO_WEEK1_WDAY 4 // Thursday
#define YDAY_MINIMUM (-366)
int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7;
return (yday
function iso_week_days($yday, $wday) {
return $yday - (($yday - $wday + 382) % 7) + 3;
}
function get_week_number($timestamp) {
$d = getdate($timestamp);
$days = iso_week_days($d["yday"], $d["wday"]);
if ($days < 0) {
$d["yday"] += 365 + is_leap_year(--$d["year"]);
$days = iso_week_days($d["yday"], $d["wday"]);
} else {
$d["yday"] -= 365 + is_leap_year($d["year"]);
$d2 = iso_week_days($d["yday"], $d["wday"]);
if (0 <= $d2) {
/* $d["year"]++; */
$days = $d2;
}
}
return (int)($days / 7) + 1;
}
?>