Easy way to get day number of current quarter?

后端 未结 9 1965
暖寄归人
暖寄归人 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:23

    Assuming you mean a calendar-quarter (because a company fiscal year can start in any month of the year), you could rely on the date('z') to determine the day-of-year, and then keep a simple array of the day each quarter starts on:

    $quarterStartDays = array( 1 /* Jan 1 */, 90 /* Mar 1, non leap-year */, ... );
    

    Then with the current day-of-year you can first locate the largest start-day that's less than or equal to the day-of-year, then subtract.

    Note that you need different numbers depending on the leap year.

提交回复
热议问题