Easy way to get day number of current quarter?

后端 未结 9 1993
暖寄归人
暖寄归人 2021-01-31 18:39

PHP provides ways to get the number of the current day of the month (date(\'j\')) as well as the number of the current day of the year (date(\'z\')). Is there a way to get the n

9条回答
  •  独厮守ぢ
    2021-01-31 19:33

    function date_quarter()
    {
        return ceil(date('n', time()) / 3);
    }
    

    or

    function date_quarter()
    {
        $month = date('n');
    
        if ($month <= 3) return 1;
        if ($month <= 6) return 2;
        if ($month <= 9) return 3;
    
        return 4;
    }
    

提交回复
热议问题