php 擷取某個月的周次資訊

來源:互聯網
上載者:User

標籤:

在做統計的時候如果按照周統計 ,需要對某個月的周次資訊進行計算,如果本月頭一天不是星期一,則向上一個月取周一,本月最後的幾天如果不能正好是一周,則忽略。

例如

2019-09月計算出來的結果

2016-08-29---2016-09-04
2016-09-05---2016-09-11
2016-09-12---2016-09-18
2016-09-19---2016-09-25

具體代碼實現如下:

<?php$current_year=2016;$current_month=9;$firstday = strtotime($current_year.‘-‘.$current_month.‘-01‘);//計算本月頭一天的星期一$monday=$firstday-86400*(date(‘N‘,$firstday)-1);//計算第一個周一的日期//由於每個月只有四周 讓 $i 從 1 到 4 增加即可for ($i=1; $i <= 4; $i++) {    $start=date("Y-m-d",$monday+($i-1)*86400*7);//起始周一    $end=date("Y-m-d",$monday+$i*86399*7);//結束周日    echo $start.‘---‘.$end."<br/>";//開始結束放入數組}?>

 

php 擷取某個月的周次資訊

聯繫我們

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