Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP Date Problem

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #33381
    xyzoblivion
    Member

    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 …

    #82874
    xyzoblivion
    Member

    and one more thing … the dates should be in DD/MM/YY format eg. . 10/07/11 would mean 10th July, 2011.

    #82876
    xyzoblivion
    Member

    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;
    }

    #82877
    xyzoblivion
    Member

    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;
    }

    #82879
    Rob MacKay
    Participant

    Well done :D

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.