get startdate and enddate for current quarter php

前端 未结 19 1676
悲哀的现实
悲哀的现实 2020-12-29 10:58

I am trying to set a start date and end date by the quarter.

For example, I am working on a reporting system where i need to report data for quarter 1, quarter 2, qu

19条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-29 11:35

    $monthsFromStart = (date('n') - 1) % 3; // 0, 1, 2, 0, 1, 2, ...
    $monthsToEnd = 2 - $monthsFromStart; // 2, 1, 0, 2, 1, 0, ...
    
    $startDay = new DateTime("first day of -$monthsFromStart month midnight");
    $endDay = new DateTime("last day of +$monthsToEnd month midnight");
    

提交回复
热议问题