get startdate and enddate for current quarter php

前端 未结 19 1549
悲哀的现实
悲哀的现实 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:40

    I'm not sure why this is so difficult - several solutions were really close here but were failing to find the FIRST and LAST day of a quarter. Quarters don't end on the first!

    Modified from KLOZ above:

        $current_quarter = ceil(date('n') / 3);
        $first_day_of_this_quarter = date('m/d/Y', strtotime(date('Y').'-'.(($current_quarter*3)-2).'-1'));
        $last_day_of_this_quarter = date('m/d/Y', strtotime(date('Y').'-'.($current_quarter*3).'-'.(date("t",date('Y').'-'.($current_quarter*3).'-1'))));
    
    0 讨论(0)
提交回复
热议问题