Skip to content

Instantly share code, notes, and snippets.

@libo1106
Created December 2, 2013 12:23
Show Gist options
  • Save libo1106/7748731 to your computer and use it in GitHub Desktop.
Save libo1106/7748731 to your computer and use it in GitHub Desktop.
统计上周、上个月的工作日
<?php
function _countWorkDate(){
$arrayDays = []; // 计算周期内总工作日
$holiday = array(
'2013-01-01','2013-01-02','2013-01-03',
'2013-02-09','2013-02-10','2013-02-11','2013-02-12','2013-02-13','2013-02-14','2013-02-15',
'2013-04-04','2013-04-05','2013-04-06',
'2013-04-29','2013-04-30','2013-05-01',
'2013-06-10','2013-06-11','2013-06-12',
'2013-09-19','2013-09-20','2013-09-21',
'2013-10-01','2013-10-02','2013-10-03','2013-10-04','2013-10-05','2013-10-06','2013-10-07'
);
$dateType = isset($_GET['t']) ? $_GET['t'] : 1;
switch($dateType){
case 1:// 周报
$calDaysLastCycle = 7;
for($i = 1; $i <= $calDaysLastCycle; $i++){
$mktime = mktime(0,0,0,date('m'),date('d')-7-date('w')+$i, date('Y'));
if(getdate($mktime)['wday'] !== 0 && getdate($mktime)['wday'] !== 6 ){
array_push($arrayDays, date('Y-m-d',$mktime));
}
}
break;
case 2:// 月报
$calDaysLastCycle = date('t', mktime( 0,0,0, date('m') - 1, 1, date('Y')));
for($i=1 ; $i <= $calDaysLastCycle ; $i++){
$mktime = mktime(0,0,0,date('m') - 1, $i, date('Y'));
if(getdate($mktime)['wday'] !== 0 && getdate($mktime)['wday'] !== 6 ){
array_push($arrayDays, date('Y-m-d',$mktime));
}
}
break;
}
$arrayDays = array_diff($arrayDays, $holiday);
return count($arrayDays);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment