get startdate and enddate for current quarter php

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

    Some answers are way too complicated IMO

    public function getStartOfQuarter()
    {
         return date(sprintf('Y-%s-01', floor((date('n') - 1) / 3) * 3 + 1));
    }
    
    public function getEndOfQuarter()
    {
        return date(sprintf('Y-%s-t', floor((date('n') + 2) / 3) * 3));
    }
    

提交回复
热议问题