php獲取月頭月末

private function getCurMonthLastDay($date) {
   return date('Y-m-d', strtotime(date('Y-m-01', strtotime($date)) . ' +1 month -1 day'));
}

private function getWeekRange($date) {
   if(!is_int($date)){
      $date = strtotime($date);
   }
   // 獲取日期是周幾
   $w = date('w', $date);

   if($w == 1){
      $startdate = date('Y-m-d', $date);
      $enddate = date('Y-m-d', strtotime('+6 days', $date));
   }else if($w == 0){
      $startdate = date('Y-m-d', strtotime('-6 days', $date));
      $enddate = date('Y-m-d', $date);
   }else{
      $startdate = date('Y-m-d', strtotime('-'.($w - 1).' days', $date));
      $enddate = date('Y-m-d', strtotime('+'.(7 - $w).' days', $date));
   }
   return array($startdate, $enddate);
}
相關文章
相關標籤/搜索