Print Y-m-d list of business dates between two dates from MySQL using PHP

后端 未结 2 824
旧巷少年郎
旧巷少年郎 2021-01-28 00:45

I have this MySQL table:

desc studentabsence;
+---------------------------+-------------+
| Field                     | Type        |
+-------------         


        
2条回答
  •  长发绾君心
    2021-01-28 01:06

    This will print the range of dates:

    $startDate = '2012-08-01';
    $endDate = '2012-08-08';
    
    $date = new DateTime($startDate);
    while ($date->format('Y-m-d') != $endDate) {
    
        if ($date->format('N') > 5) {
            $date->modify('+1 day');
            continue;
        }
    
        echo $date->format('Y-m-d') . PHP_EOL;
        $date->modify('+1 day');
    }
    echo $endDate;
    

提交回复
热议问题