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;}
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.