จดๆไว้ก่อน
ย้อนกลับไป 365 วัน
SQL : DATE_SUB(CURDATE(),INTERVAL 365 DAY)
// เปรียบเทียบวันที่ในรูปแบบ string (yyyy-mm-dd) ของ mysql สองค่า
// คืนค่าเป็นตัวเลข 0-เท่ากัน , 1-ค่าแรกมากกว่า , 2-ค่าสองมากกว่า
function func_cmpDate($date1,$date2) {
$arrDate1 = explode("-",$date1);
$arrDate2 = explode("-",$date2);
$timStmp1 = mktime(0,0,0,$arrDate1[1],$arrDate1[2],$arrDate1[0]);
$timStmp2 = mktime(0,0,0,$arrDate2[1],$arrDate2[2],$arrDate2[0]);
if ($timStmp1 == $timStmp2) {
return 0; // เท่ากัน
} else if ($timStmp1 > $timStmp2) {
return 1; // ค่าแรกมากกว่า
} else if ($timStmp1 < $timStmp2) {
return 2; // ค่าสองมากกว่า
}
}
/* func_explodedate ใช้ข้อมูลวันที่ในรูปของ text (yyyy-mm-dd) เพื่อหาและคืนค่าต่างๆแบบ array */
function func_explodedate($textdate){
$arrDate = explode("-",$textdate);
return array(
'weekday' => date("l", strtotime($arrDate[0]."-".$arrDate[1]."-".$arrDate[2])),
'day' => $arrDate[2],
'month' => $arrDate[1],
'year' => $arrDate[0],
'lastday_d' => date("Y-m-t", strtotime($arrDate[0]."-".$arrDate[1]."-".$arrDate[2])), // วันสิ้นเดือน date type
'lastday_n' => date("t", strtotime($arrDate[0]."-".$arrDate[1]."-".$arrDate[2])) // วันสิ้นเดือน numeric type
);
}
อื่นๆ
echo "ปีคศ. ปัจจุบัน : ".date("Y")."\n";
echo "วันแรกของปี : ".date('Y-m-01',strtotime(date("Y")."-01-01"))."\n";
echo "วันแรกของเดือน : ".date('Y-m-01',strtotime(date("Y")."-".date("m")."-01"))."\n";
echo "วันสิ้นเดือน : ".date('Y-m-t',strtotime(date("Y")."-".date("m")."-01"))."\n";
0 ความคิดเห็น