php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34797 strtotime() and strtointerval()
Submitted: 2005-10-09 23:17 UTC Modified: 2012-02-21 07:19 UTC
From: saverio dot caminiti at alfanet dot it Assigned: rasmus (profile)
Status: Closed Package: *General Issues
PHP Version: 5.0.5 OS: Irrelevant
Private report: No CVE-ID: None
 [2005-10-09 23:17 UTC] saverio dot caminiti at alfanet dot it
Description:
------------
The function strtotime() is really useful.
But it always returns the minimum timestamp that match the input string. It should be even more useful to have a function strtointerval that return a two timestamps: the minimum timestamp that match the input and the maximum one.
For example:
- strtointerval(?Dec 3 2004?) should returns a minimum timestamp (0:0:0 Dec 3 2004) and a maximum one (23:59:59 Dec 3 2004). 
- strtointerval(?Dec 2004?) returns 0:0:0 Dec 1 2004 and 23:59:59 Dec 31 2004
- strtointerval(?2004?) returns 0:0:0 Jan 1 2004 and 23:59:59 Dec 31 2004
And so on.

It should be also useful that strtointerval() parse English sentences like ?between A and B? or ?[form] A to B? where A and B are two valid input for the actual strtotime().

I guess that starting from the source code of strtotime() it should be not difficult to implement strtointerval(), perhaps through a function strtoMAXtime() that generate the maximum timestamp instead of the minimum one, and then adding the English interval sentences support.

Thanks,
Saverio.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-21 07:19 UTC] rasmus@php.net
We now have DatePeriod and DateInterval which, although isn't quite the same 
thing as this request, I think is quite a bit more useful as it lets you iterate 
using the interval across the period. And you can use strtotime() syntax to 
define the end points of the period to iterate over.
 [2012-02-21 07:19 UTC] rasmus@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: rasmus
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 06:01:32 2025 UTC