PHP Classes

PHP Date Interval: Perform calculations with date intervals

Recommend this page to a friend!
  Info   View files Documentation   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 174 This week: 1All time: 8,783 This week: 560Up
Version License PHP version Categories
date-frame 1.1MIT/X Consortium ...5.3PHP 5, Time and Date, Databases
Description 

Author

This class can perform calculations with date intervals.

It takes a start and a begin date and performs several types of calculations related with the interval defined by those dates.

Currently it can check if a date is within an interval, check if two intervals overlap, generate SQL BETWEEN clauses to check if an expression is within the date range, get the list of days in the interval separated by days, weeks, months, quarters or years.

Picture of David Giglio
  Performance   Level  
Name: David Giglio <contact>
Classes: 1 package by
Country: United States United States
Age: ???
All time rank: 4220537 in United States United States
Week rank: 411 Up48 in United States United States Up

Documentation

DateFrame

PHP DateFrame class to ease working with date intervals (date ranges), and ease generation of SQL BETWEEN clauses

Contructor requires start and end date in any format readable aby PHP's strtotime function

$dateframe = new DateFrame('2015-01-01', '3/31/2015');
/
 * DateFrame Object
 * (
 *   [start] => 2015-01-01 00:00:00
 *   [end] => 2015-03-31 23:59:59
 *   [days] => 90
 *   [criteria] => 
 *   [orig_start] => 2015-01-01
 *   [orig_end] => 3/31/2015
 * )
 */

Each DateFrame can then be broken into an array of shorter interval DateFrames broken down by: day, seven days, Sun-Sat weeks, n months, fiscal quarters, n years.

$by_month = $dateframe->asMonthIntervals(); 
/
 * $by_month set to array of three DateFrame objects: Jan., Feb., Mar.
 *
 * Array
 * (
 *   [0] => DateFrame Object
 *       (
 *          [start] => 2015-01-01 00:00:00
 *          [end] => 2015-01-31 23:59:59
 *          [days] => 31
 *          [orig_start] => 2015-01-01
 *          [orig_end] => 2015-01-31
 *          [interval] => 1M
 *      )
 *
 *  [1] => DateFrame Object
 *      (
 *          [start] => 2015-02-01 00:00:00
 *          [end] => 2015-02-28 23:59:59
 *          [days] => 28
 *          [orig_start] => 2015-02-01
 *          [orig_end] => 2015-02-28
 *          [interval] => 1M
 *      )
 *
 *   [2] => DateFrame Object
 *      (
 *          [start] => 2015-03-01 00:00:00
 *          [end] => 2015-03-31 23:59:59
 *          [days] => 31
 *          [orig_start] => 2015-03-01
 *          [orig_end] => 2015-03-31
 *          [interval] => 1M
 *      )
 * )
 */

Methods to check if DateFrame contains date, or DateFrame overlaps another DateFrame.

$dateframe->contains('2/1/2015'); // equals true

$dateframe2 = new DateFrame('2014-01-01', '3/31/2014');
$dateframe->overlaps($dateframe2); // equals false

Method to create SQL BETWEEN clause

$dateframe = new DateFrame('2015-01-01', '3/31/2015');
$between = $dateframe->getCriteria('completed_date');
/
 * DateFrame Object
 * (
 *   [start] => 2015-01-01 00:00:00
 *   [end] => 2015-03-31 23:59:59
 *   [days] => 90
 *   [criteria] => completeddate BETWEEN '2015-01-01 00:00:00' AND '2015-03-31 23:59:59'
 *   [orig_start] => 2015-01-01
 *   [orig_end] => 3/31/2015
 * )
 */


  Files folder image Files  
File Role Description
Plain text file DateFrame.php Class Class source
Accessible without login Plain text file DateFrame_Test.php Test Unit test script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:174
This week:1
All time:8,783
This week:560Up