|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76622 Support "quarter" keyword as relative format for DateTime
Submitted: 2018-07-14 17:02 UTC Modified: 2021-07-28 10:17 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: thomas at landauer dot at Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: thomas at landauer dot at
New email:
PHP Version: OS:


 [2018-07-14 17:02 UTC] thomas at landauer dot at
Considering the fact that \DateTime() does support some really exotic input (like e.g. "last sat of July 2008"), it would be nice to have some quarter-related formats too:
* "first|last day of last|this|next quarter"

Or maybe even:
* "first|last day of quarter 4 2008" or "first|last day of fourth quarter 2008"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-15 02:39 UTC]
The problem is that there are multiple ways to define a quarter. Jan 1 - Mar 31 is what the (Gregorian) calendar says for the first quarter, but quarters are more commonly used in a fiscal sense and their definitions can vary wildly.

See also bug #15184, but it's been more than a decade so I think this is worth a second thought. Perhaps just going with the simple Gregorian version - which can often be used to derive others.
 [2018-07-15 03:37 UTC] a at b dot c dot de
Although in some of those "other" cases you still need to know the month to make the right adjustment - and if you have that you can calculate the quarter anyway.
 [2018-07-15 03:47 UTC]
For some, yes, but most of them I saw are based on the calendar year so chaining one or two relative amounts should get the job done. For example, US federal is one quarter behind the calendar; its Q1 2018 started Oct 1 2017 and you could get it with "quarter 1 2018 -3 months".
 [2018-07-15 07:51 UTC] a at b dot c dot de
That would work (I'd be using "+ 3 months" and "+ 5 months"); the suggestion in the other bug you cite (#15184) for date('q') on the other hand would be useless for a year starting in June.

It's the difference between "get a timestamp for a given quarter" and "get a quarter for a given timestamp". The former would actually be easier.
 [2018-07-15 08:32 UTC]
Yeah, adding or subtracting months creates a risk of overflowing/underflowing dates resulting in wrong results for a few days of each year. It's okay for the quarter-to-timestamp direction since the quarter would "be" on the 1st of some month, but going in reverse you'd have to deal with February and 31sts.

The issue is complicated enough to prove it needs its own library. As for PHP, I'm still hoping there's some simple solution that can at least be a starting point for most use cases.
 [2018-07-15 11:36 UTC] thomas at landauer dot at
Sorry, that other bug didn't show up when I searched for "quarter".

When it comes to calendars, *anything* is a mess. E.g. it isn't even universally clear which year we have:

But: I have never heard from any other quarters than these:
Even mainly sticks to that, some ambiguity is just about the *numbering* of the quarters. So "first|last day of last|this|next quarter" should be fine for everybody.

And there have been even more tricky questions in the past, for which finally a common solution could be agreed upon, e.g.:
> Weeks always start on monday. Formerly, sunday would also be considered to start a week.
 [2021-07-28 10:17 UTC]
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2021-07-28 10:17 UTC]
Bug #15184 has been re-opened in the meantime, so I'm closing this
as duplicate.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Jul 31 12:01:27 2021 UTC