Get dropdown list between two date range excluding weekends in PHP

Please note, this is not a tested code. Please let me know if any issue you face.

<?php
$start = '2019/01/01'; //start date
$end = '2019/01/30'; //end date

$currentDate = strtotime($start);
$endDate = strtotime($end);
$dates = array();

while ($currentDate <= $endDate ) {
    if(!isWeekend($currentDate)){
        $dates[] = date('Y/m/d', $currentDate );
    }
    $currentDate = strtotime('+1 days', $currentDate );
}

function isWeekend($date) {
    return date('w', $date) == 0 || date('w', $date) == 6;
}
?> 

Next you need to create your select tag like this:

<select name=date_range=>
<?PHP
    for($i = 0; $i < count($dates); $i++) {
        echo "<option value='{$dates[$i]}'>";
        echo date("Y/m/d - l", strtotime($dates[$i]));
        echo "</option>";
    }
?>



</select>

Comments