ลำดับตอนที่ #29
คืนค่าการตั้งค่าทั้งหมด
คุณแน่ใจว่าต้องการคืนค่าการตั้งค่าทั้งหมด ?
ลำดับตอนที่ #29 : [PHP] เรียงวันที่ เริ่มต้น - วันสุดท้ายของเดือน
<?
//เรียงวันที่ เริ่มต้น - วันสุดท้ายของเดือน
function date_in_period($format, $start, $end, $skip = NULL){
$output = array();
$days = floor((strtotime($end) - strtotime($start))/86400);
for($i=0;$i<=$days;$i++){
$in_period = strtotime("+" . $i . " day", strtotime($start));
if(is_array($skip) and in_array(date("D",$in_period), $skip)){
continue;
}
array_push($output, date($format, $in_period));
}
return $output;
}
//เช็ควันสุดท้ายของเดือน
$day = array(31, 30, 29, 28);
$month = date("m");
$year = date("Y")+543;
for($i=0; $i < count($day); $i++)
{
$day_check = $day[$i];
if(checkdate($month, $day_check, $year))
{
$last_date = "$day_check";
break;
}
}
$dateStart = date('Y-m').'-'.'01';
$dateEnd = date('Y-m').'-'.$last_date;
$date = date_in_period("d/m/Y", $dateStart, $dateEnd);
foreach($date as $day){
echo $day . "<br / >";
}
echo "Total : " . count($date) . " days<br / >";
?>
credit :
http://www.thaicreate.com/php/forum/058373.html
http://www.thaicreate.com/php/forum/043013.html
เก็บเข้าคอลเล็กชัน
ความคิดเห็น