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: 2018-11-16 00:43 UTC
Votes:9
Avg. Score:3.8 ± 1.3
Reproduced:8 of 8 (100.0%)
Same Version:1 (12.5%)
Same OS:2 (25.0%)
From: j-f at gmx dot net Assigned:
Status: Re-Opened Package: Date/time related
PHP Version: 7.2 OS: -
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Mar 21 05:01:26 2019 UTC