Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Split a Time Slot Between the Start and End Time Using the Time Interval

    This is a user-defined PHP function that is used to split a time slot between the start and end time using time intervals.

    The function takes a start time, end time, and time interval as input and gives an array as the output.

    Function:
    function SplitTime($StartTime, $EndTime, $Duration="60"){
        $ReturnArray = array ();// Define output
        $StartTime    = strtotime ($StartTime); //Get Timestamp
        $EndTime      = strtotime ($EndTime); //Get Timestamp
    
        $AddMins  = $Duration * 60;
    
        while ($StartTime <= $EndTime) //Run loop
        {
            $ReturnArray[] = date ("G:i", $StartTime);
            $StartTime += $AddMins; //Endtime check
        }
        return $ReturnArray;
    }
    
    //Calling the function
    $Data = SplitTime("2018-05-12 12:15", "2018-05-12 15:30", "60");
    echo "<pre>";
    print_r($Data);
    echo "<pre>";

    Output:

    Array
    (
        [0] => 12:15
        [1] => 13:15
        [2] => 14:15
        [3] => 15:15
    )


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.