php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #15184 Calculate the quarter with date('Q')?
Submitted: 2002-01-23 11:44 UTC Modified: 2021-10-01 16:36 UTC
Votes:28
Avg. Score:3.6 ± 0.9
Reproduced:16 of 18 (88.9%)
Same Version:9 (56.2%)
Same OS:5 (31.2%)
From: j-f at gmx dot net Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 7.2 OS: -
Private report: No CVE-ID: None
 [2002-01-23 11:44 UTC] j-f at gmx dot net
I added a note how to calculate the quarter:
ceil(date('n')/3);

But I suggest extending date() with the option 'Q' or 'q'.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-11 19:22 UTC] nlopess@php.net
One more for you, Derick :)
 [2005-08-12 08:46 UTC] derick@php.net
Some people have different opinions on when the quarter starts. Just saying that it starts at january 1 is in correct, as most people start Q1 in the first week of the year or something. That's why I don't think we should add this.
 [2011-02-21 21:18 UTC] fernandojmartin at gmail dot com
Why not to just follow the way MySQL behaves?

In that way I'm not obligated to calculate part of the date OUTSIDE the DB server!

The YEAR starts on Jan 1st. Period.
The first week of the year has nothing to do with Q1 if the real date is December 
31.
I don't see a clear sustenance in derick's explanation.
 [2013-04-18 16:07 UTC] programming at stefan-koch dot name
I really cannot see from where you derive that "most people start Q1 in the first week of the year or something". Whereever I look after a Google search, the definition of the quarters is:

First quarter: from the beginning of January to the end of March
Second quarter: from the beginning of April to the end of June
Third quarter: from the beginning of July to the end of September
Fourth quarter: from the beginning of October to the end of December

German Wikipedia lists it even clearer, should also be understandable to English speaking people:

http://de.wikipedia.org/wiki/Quartal#Quartale_und_ihre_Monate

e.g. Quarter I from 1. January to 31. March.

I already submitted a patch in another feature request [1], but judging from PHP's behaviour, I am pretty sure that nobody will ever implement it (I would understand that MY implementation is not good enough to be copied).
I want to mention that PHP dev's argumentation as I see it in many bug reports really keeps me from diving into PHP interpreter development.


[1] https://bugs.php.net/bug.php?id=34932
 [2018-04-23 12:10 UTC] vickron at yahoo dot com
if cannot implement date('q') 
at least should implemented strtotime('first day of quarter') ...
its annoying using some interpreted code just to wrap around this...
ceil(date('n')/3) just return the quarter number...
need to calc month 1 to 1-january 2-april 3-july and 4-october
using first_month_of_quarter = ceil(date('n')/3) * 3 -2;
date('Y-m-d', mktime (0,0,0,ceil(date('n')/3) * 3 -2,1,date('Y')));
 [2018-10-13 01:39 UTC] love at sickpeople dot se
GNU coreutils added support for %q in 2016. See https://savannah.gnu.org/forum/forum.php?forum_id=8745

The value is 1 - 4.
 [2018-10-13 02:39 UTC] requinix@php.net
-Package: Feature/Change Request +Package: *General Issues
 [2018-10-13 02:39 UTC] requinix@php.net
If coreutils/date has it then I think it's worth reconsidering - GNU has already decided what a quarter is and PHP would merely be consistent with that, like it already is when it comes to other date handling problems.
 [2018-11-15 15:46 UTC] love at sickpeople dot se
@requinix: could you please change the status from Wont fix to Open again?
 [2018-11-15 17:04 UTC] requinix@php.net
-Status: Wont fix +Status: Re-Opened -PHP Version: 4.1.1 +PHP Version: 7.2 -Assigned To: derick +Assigned To:
 [2018-11-16 00:43 UTC] cmb@php.net
-Package: *General Issues +Package: Date/time related
 [2021-10-01 14:32 UTC] lbarkley at gmail dot com
@cmb Can you actually do something to help the community instead of just opening/reassigning issues? Are you a recently hired project manager?
 [2021-10-01 16:36 UTC] derick@php.net
-Status: Re-Opened +Status: Wont fix
 [2021-10-01 16:36 UTC] derick@php.net
This is still a "Wont fix" for previously mentioned reasons.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC