2 回答
TA贡献1824条经验 获得超6个赞
创建一个 dates.json 文件并像这样粘贴您要排除的所有日期
{
"dates" : [
"2019-05-01",
"2019-06-01"
]
}
在您的 php 中,将这些日期读取为
$holidays = file_get_contents('dates.json');
$holidays = json_decode($holidays, true);
$holidays = $holidays['dates'];
现在你的假期变量有两个日期。
TA贡献1796条经验 获得超4个赞
<?php
$joiningdate= date_create($row['jdate']); // Fetching this from database
$tdate = date('Y-m-d');
$todaydate1=date_create($tdate);
$todaydate1->modify('+1 day');
$interval=date_diff($todaydate1,$joiningdate);
$days = $interval->days;
// creating an iterateable period of date (P1D equates to 1 day)
$period = new DatePeriod($joiningdate, new DateInterval('P1D'), $todaydate1);
// Storing holidays in a array to exclude
$holidays = array('2019-01-15','2019-01-26','2019-03-04','2019-05-01','2019-08-15','2019-09-02','2019-10-02','2019-09-08', '2019-11-01');
$return_data_set=array();
foreach($period as $dt) {
$curr = $dt->format('D');
// substract holidays
if (in_array($dt->format('Y-m-d'), $holidays)) {
$return_data['holiday'][]=$dt->format('Y-m-d');
}
else{
$return_data['working_days'][]=$dt->format('Y-m-d');
}
}
print_r($return_data['working_days']);
?>
- 2 回答
- 0 关注
- 127 浏览
添加回答
举报