Lid |
|
Of je kan dit gebruiken
function getDateFromWeek($iWeek, $iYear)
{
// Get a random monday in the requested year
$iRandomDate = mktime(0, 0, 0, 3, 1, $iYear);
// What's the first monday before this random date?
$iMonday = mktime(0, 0, 0, date('n', $iRandomDate), date('j', $iRandomDate)-(date('w', $iRandomDate)-1), $iYear);
// Get the date of week 1
$iFirstWeek = mktime(0, 0, 0, date('n', $iMonday), date('j', $iMonday) - 7*(date('W', $iMonday)-1), $iYear);
return mktime(0, 0, 0, date('n', $iFirstWeek), date('j', $iFirstWeek) + 7*($iWeek-1), date('Y', $iFirstWeek));
}
function getEndDateFromWeek($iWeek, $iYear)
{
// Get a random sunday in the requested year
$iRandomDate = mktime(0, 0, 0, 3, 1, $iYear);
// What's the first sunday before this random date?
$iSunday = mktime(0, 0, 0, date('n', $iRandomDate), date('j', $iRandomDate)-(date('w', $iRandomDate)-7), $iYear);
$iWeekend = mktime(0, 0, 0, date('n', $iSunday), date('j', $iSunday) - 7*(date('W', $iSunday)-1), $iYear);
return mktime(0, 0, 0, date('n', $iWeekend), date('j', $iWeekend) + 7*($iWeek-1), date('Y', $iWeekend)) ;
}
echo date('d/m/Y', getDateFromWeek(date("W"), date("Y"))) . " - " . date('d/m/Y', getEndDateFromWeek(date("W"), date("Y")));
function getDateFromWeek($iWeek, $iYear) { // Get a random monday in the requested year $iRandomDate = mktime(0, 0, 0, 3, 1, $iYear); // What's the first monday before this random date? $iMonday = mktime(0, 0, 0, date('n', $iRandomDate), date('j', $iRandomDate)-(date('w', $iRandomDate)-1), $iYear); // Get the date of week 1 $iFirstWeek = mktime(0, 0, 0, date('n', $iMonday), date('j', $iMonday) - 7*(date('W', $iMonday)-1), $iYear); return mktime(0, 0, 0, date('n', $iFirstWeek), date('j', $iFirstWeek) + 7*($iWeek-1), date('Y', $iFirstWeek)); } function getEndDateFromWeek($iWeek, $iYear) { // Get a random sunday in the requested year $iRandomDate = mktime(0, 0, 0, 3, 1, $iYear); // What's the first sunday before this random date? $iSunday = mktime(0, 0, 0, date('n', $iRandomDate), date('j', $iRandomDate)-(date('w', $iRandomDate)-7), $iYear); $iWeekend = mktime(0, 0, 0, date('n', $iSunday), date('j', $iSunday) - 7*(date('W', $iSunday)-1), $iYear); return mktime(0, 0, 0, date('n', $iWeekend), date('j', $iWeekend) + 7*($iWeek-1), date('Y', $iWeekend)) ; }
|