Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy way to get day number of current quarter?

Tags:

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 number of the current day of the current quarter?

So right now, August 5, it is day 36 of the third quarter.

If there is no standard way of calculating this, does anyone have a (prefereably PHP-based) algorithm handy?

like image 475
Chad Johnson Avatar asked Aug 05 '09 16:08

Chad Johnson


People also ask

How do I extract a date from a quarter in Excel?

Find and get quarter from date by formula Select a blank cell which next to the date, here I select C1, and type this formula =ROUNDUP(MONTH(A1)/3,0) into it, then press Enter key to get the relative quarter.

How do you get a quarter in SQL?

In SQL Server, you can use DATEPART(QUARTER,whn) and YEAR(whn) . In Oracle, you can use TO_CHAR(whn,'Q') and TO_CHAR(whn,'YYYY') for the quarter and year. In PostgreSQL, you can use EXTRACT(QUARTER FROM whn) and EXTRACT(YEAR FROM whn) . In Access, you can use DatePart("q", whn) and YEAR(whn) .


1 Answers

How about:

$curMonth = date("m", time()); $curQuarter = ceil($curMonth/3); 
like image 51
Michiel Avatar answered Oct 09 '22 06:10

Michiel