|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34932 Quarter as parameter in the Date function
Submitted: 2005-10-20 16:32 UTC Modified: 2017-01-11 06:51 UTC
Avg. Score:4.7 ± 0.5
Reproduced:6 of 6 (100.0%)
Same Version:1 (16.7%)
Same OS:2 (33.3%)
From: sandved at gmail dot com Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 5.1.0RC3 OS:
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: sandved at gmail dot com
New email:
PHP Version: OS:


 [2005-10-20 16:32 UTC] sandved at gmail dot com
(I tried to add an argument to but didn't succeeded):

The Date function may need a way to display a quarter defined standard (in SQL for example) as follow

Value Description
1 - Period January/March
2 - Period April/June
3 - Period July/Sep
4 - Period Oct/December

by using Q as an parameter as in SQL -

Reproduce code:
new feature

Expected result:
date('Y\-\QQ') returns 

2005-Q1 for all dates 2005-01-01/2005-03-31
2005-Q2 for all dates 2005-04-01/2005-06-30
2005-Q3 for all dates 2005-07-01/2005-09-30
2005-Q4 for all dates 2005-10-01/2005-12-31

2005-Q1 for the date 2005-02-09
2005-Q4 for the date 2005-12-14

Actual result:
new feature


add-date-quarter-support (last revision 2013-04-01 15:50 UTC by programming at stefan-koch dot name)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-30 23:14 UTC]
-Package: Feature/Change Request +Package: Date/time related
 [2017-01-11 06:51 UTC]
-Status: Open +Status: Wont fix
 [2017-01-11 06:51 UTC]
This can easily be done in userland. Having that in the library only adds to the complexity and is therefore discouraged.

You can get the value you want for example using

$date = new DateTime('2017-04-01'); 
echo floor($date->format('m') / 4) + 1
 [2018-10-13 01:37 UTC] love at sickpeople dot se
The point of having q/Q is that you can pass a format to some method that will compare dates based on the given format.

It's useful if you want to do foo('Y-m-00'), foo('Y-q'), foo('Y-W') etc.

You don't have to do something like

$date = $datetime->format(str_replace('q', ceil($datetime->format('m') / 3), $format));

As for "easily be done in userland". Your code is actually wrong.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 21:01:28 2024 UTC