我有这个 MySQL
表:
desc studentabsence;
+---------------------------+-------------+
| Field | Type |
+---------------------------+-------------+
| student_id | INT(11) |
| student_absence_startdate | date |
| student_absence_enddate | date |
+---------------------------+-------------+
假设我们有
student_absence_startdate = 2012-08-01
student_absence_enddate = 2012-08-08
使用 PHP,我想回显
该范围(周一至周五)之间的所有工作日。
从上面的范围我想打印:
2012-08-01
2012-08-02
2012-08-03
2012-08-06
2012-08-07
2012-08-08
我应该如何以及从哪里开始实现这一目标?
最佳答案
// Date strings from DB
$startDate = '2012-08-01';
$endDate = '2012-08-08';
// Convert to UNIX timestamps
$currentTime = strtotime($startDate);
$endTime = strtotime($endDate);
// Loop until we reach the last day
$result = array();
while ($currentTime <= $endTime) {
if (date('N', $currentTime) < 6) {
$result[] = date('Y-m-d', $currentTime);
}
$currentTime = strtotime('+1 day', $currentTime);
}
// Show the result
// You could loop the array to pretty-print it, or do it within the above loop
print_r($result);
关于php - 使用 PHP 从 MySQL 打印两个日期之间的 Y-m-d 业务日期列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11904033/