By week and yr i get 1st and last day of week, but... SOLVED
Posted: Mon May 26, 2008 12:01 pm
By week and yr i get 1st and last day of week:
<?php
$dia='13-08-2008';
list($d, $m, $y) = explode('-', $dia);
$week=date('W',strtotime("$y-$m-$d"));
function week_start_date($wk_num, $yr, $first = 1, $format = 'F d Y')
{
$wk_ts = strtotime('+' . $wk_num . ' weeks', strtotime($yr . '0101'));
$mon_ts = strtotime('-' . date('w', $wk_ts) + $first . ' days', $wk_ts);
return date($format, $mon_ts);
}
$sStartDate = week_start_date($week-1, $y);
$sEndDate = date('d-m-Y', strtotime('+6 days', strtotime($sStartDate)));
print "week: $week, start: $sStartDate, end: $sEndDate";
?>
but i get:
week: 33, start: August 11 2008, end: 17-08-2008
and i want:
week: 33, start: 11-08-2008, end: 17-08-2008
i tried to change the format at the function:
$format = 'm-d-Y'
so i could explode, but it gives a:
Warning: date(): Windows does not support dates prior to midnight (00:00:00), January 1, 1970
and it prints the start date correct: start: 08-11-2008 but then i can't process the end date..
can someone help me with this?
thanks a lot
<?php
$dia='13-08-2008';
list($d, $m, $y) = explode('-', $dia);
$week=date('W',strtotime("$y-$m-$d"));
function week_start_date($wk_num, $yr, $first = 1, $format = 'F d Y')
{
$wk_ts = strtotime('+' . $wk_num . ' weeks', strtotime($yr . '0101'));
$mon_ts = strtotime('-' . date('w', $wk_ts) + $first . ' days', $wk_ts);
return date($format, $mon_ts);
}
$sStartDate = week_start_date($week-1, $y);
$sEndDate = date('d-m-Y', strtotime('+6 days', strtotime($sStartDate)));
print "week: $week, start: $sStartDate, end: $sEndDate";
?>
but i get:
week: 33, start: August 11 2008, end: 17-08-2008
and i want:
week: 33, start: 11-08-2008, end: 17-08-2008
i tried to change the format at the function:
$format = 'm-d-Y'
so i could explode, but it gives a:
Warning: date(): Windows does not support dates prior to midnight (00:00:00), January 1, 1970
and it prints the start date correct: start: 08-11-2008 but then i can't process the end date..
can someone help me with this?
thanks a lot