Possible Duplicate:
Finding date range for current week, month and year
Can Anyone help me on how could I generate Friday cutoff using PHP or MySQL. below is the sample date range
...
2012-10-06 to 2012-10-12
2012-10-13 to 2012-10-19
2012-10-20 to 2012-10-26
...
2012-12-22 to 2012-12-28
2012-12-29 to 2013-01-04
Knowing the first saturday (the initial period) is easy to calculate the next friday (and looping the next saturday, next friday of second saturday....)
Check this code:
<?php
$saturday = '2012-10-06';
$next_friday = date('Y-m-d', strtotime('+6 days', strtotime($saturday)));
print "The next friday is $next_friday";
Try this code ...
function getCurrentWeek($start , $end){
$ts = strtotime($start);
$te = strtotime($end);
$days = round(abs($te-$ts)/86400);
$range = '';
$j = 0;
// generate dates
for ($i=0; $i<$days; $i++, $ts+=86400){
$temp_date = date("Y-m-d", $ts);
$d = (int) date('w',$ts);
switch ($d) {
case 5 :
if($j == 1)
$range .= $temp_date . "<br />" ;
$j = 0;
break;
case 6 :
$j = 1;
$range .= $temp_date . " TO " ;
break;
}
}
return $range;
}
echo getCurrentWeek('2012-10-06','2013-01-06');
Ps) You need to input correct start and end date where you have a Friday at the end ... or you will have XXXX-XX-XX TO EMPTY