- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hello all,
I have just ruined my evening trying to solve a problem in PHP. I am starting to feel very demoralized now … css-tricks’ forum is my only hope :)
Okay the problem is that i have 2 text fields one is the “Start Date” and the other is “End Date” users have to enter dates into it and the script has to generate the range of dates
“EXCLUDING SUNDAYS”. I tried everything but i am an ultimate beginner
Please help me out to solve this problem .. thanks in advance …
and one more thing … the dates should be in DD/MM/YY format eg. . 10/07/11 would mean 10th July, 2011.
Wow .. at last i have done it ! you guys may want to look at this ..
function excludeSundays($dates_range)
{
$dates_wo_sundays = array();
for($i=0;$i
$dates2 = explode(“/”,$dates_range[$i]);
$dates_range[$i] = date(‘d/m/y’,mktime(0,0,0,$dates2[1],$dates2[0],$dates2[2]));
$dates2 = explode(“/”,$dates_range[$i]);
$weekday = date(‘l’,strtotime($dates2[1] . “/” . $dates2[0] . “/” . $dates2[2],$date));
if($weekday != “Sunday”)
{
$dates_wo_sundays[$i] = $dates_range[$i];
//echo $date . ” is ” . $weekday . “
“;
}
}
return $dates_wo_sundays;
}
and here is how you should calculate the range …
function dateRangeArray($start, $end)
{
$range = array();
if (is_string($start) === true) $start = strtotime($start);
if (is_string($end) === true ) $end = strtotime($end);
do
{
$range[] = date(‘d/m/y’, $start);
$start = strtotime(“+ 1 day”, $start);
}
while($start <= $end);
return $range;
}
Well done :D