|
|
|
php ทำระบบลา ตรวจสอบวันเริ่มต้นและวันสิ้นสุด โดยไม่นับเสาร์อาทิตย์ และวันหยุดราชการครับ |
|
|
|
|
|
|
|
Code (PHP)
<?php
function CheckPublicHoliday($strChkDate)
{
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM public_holiday WHERE PublicHoliday = '".$strChkDate."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)
{
return false;
}
else
{
return true;
}
mysql_close($objConnect);
}
$strStartDate = "2011-08-01";
$strEndDate = "2011-08-15";
$intWorkDay = 0;
$intHoliday = 0;
$intPublicHoliday = 0;
$intTotalDay = ((strtotime($strEndDate) - strtotime($strStartDate))/ ( 60 * 60 * 24 )) + 1;
while (strtotime($strStartDate) <= strtotime($strEndDate)) {
$DayOfWeek = date("w", strtotime($strStartDate));
if($DayOfWeek == 0 or $DayOfWeek ==6) // 0 = Sunday, 6 = Saturday;
{
$intHoliday++;
echo "$strStartDate = <font color=red>Holiday</font><br>";
}
elseif(CheckPublicHoliday($strStartDate))
{
$intPublicHoliday++;
echo "$strStartDate = <font color=orange>Public Holiday</font><br>";
}
else
{
$intWorkDay++;
echo "$strStartDate = <b>Work Day</b><br>";
}
//$DayOfWeek = date("l", strtotime($strStartDate)); // return Sunday, Monday,Tuesday....
$strStartDate = date ("Y-m-d", strtotime("+1 day", strtotime($strStartDate)));
}
echo "<hr>";
echo "<br>Total Day = $intTotalDay";
echo "<br>Work Day = $intWorkDay";
echo "<br>Holiday = $intHoliday";
echo "<br>Public Holiday = $intPublicHoliday";
echo "<br>All Holiday = ".($intHoliday+$intPublicHoliday);
?>
Go to : PHP Checking Work Day , Holiday ตรวจสอบวันหยุด และวันหยุดราชการ
|
|
|
|
|
Date :
2011-08-27 18:20:55 |
By :
thaicreate |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|