PHP擷取當前星期(月份)的日期範圍_PHP教程

來源:互聯網
上載者:User

PHP擷取當前星期(月份)的日期範圍


  程式需要,寫了一個擷取當前星期的日期範圍,也就是從星期一到星期日的日期範圍。

  function getWeekRange($date){

  $ret=array();

  $timestamp=strtotime($date);

  $w=strftime('%u',$timestamp);

  $ret['sdate']=date('Y-m-d 00:00:00',$timestamp-($w-1)*86400);

  $ret['edate']=date('Y-m-d 23:59:59',$timestamp+(7-$w)*86400);

  return $ret;

  }

  //author:zhxia 擷取指定日期所在月的開始日期與結束日期

  function getMonthRange($date){

  $ret=array();

  $timestamp=strtotime($date);

  $mdays=date('t',$timestamp);

  $ret['sdate']=date('Y-m-1 00:00:00',$timestamp);

  $ret['edate']=date('Y-m-'.$mdays.' 23:59:59',$timestamp);

  return $ret;

  }

  //author:zhxia 以上兩個函數的應用

  function getFilter($n){

  $ret=array();

  switch($n){

  case 1:// 昨天

  $ret['sdate']=date('Y-m-d 00:00:00',strtotime('-1 day'));

  $ret['edate']=date('Y-m-d 23:59:59',strtotime('-1 day'));

  break;

  case 2://本星期

  $ret=getWeekRange(date('Y-m-d'));

  break;

  case 3://上一個星期

  $strDate=date('Y-m-d',strtotime('-1 week'));

  $ret=getWeekRange($strDate);

  break;

  case 4: //上上星期

  $strDate=date('Y-m-d',strtotime('-2 week'));

  $ret=getWeekRange($strDate);

  break;

  case 5: //本月

  $ret=getMonthRange(date('Y-m-d'));

  break;

  case 6://上月

  $strDate=date('Y-m-d',strtotime('-1 month'));

  $ret=getMonthRange($strDate);

  break;

  }

  return $ret;

  }

http://www.bkjia.com/PHPjc/847199.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/847199.htmlTechArticlePHP擷取當前星期(月份)的日期範圍 程式需要,寫了一個擷取當前星期的日期範圍,也就是從星期一到星期日的日期範圍。 function getWeekRang...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.