Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
PHP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
README.textile
date_time_helper.php
date_time_helper.test.php
index.php
screenshot.png
unit_test.php

README.textile

DateTime helper

Provide time details either as an array or an object and difference between times in words, timestamps and an object. Also, return a new time adding time intervals in days, week, month, etc..
View Demo :: Try it out and Rate on phpclasses.org

Uses
require 'date_time_helper.php';

// Instance of DateTime helper class
// By default helper class work with current date time
$dth = new DateTimeHelper();
Date Time parts
$dth->year(); 
$dth->month();
$dth->day();
$dth->hours();
$dth->minutes();
$dth->seconds();

//2013, 6, 24, 4, 51, 3
DateTime details as an object
$dth->time_details

$dth->toArray('2011-03-01 10:10:10');

//stdClass Object ( [y] => 2013 [m] => 6 [d] => 24 [h] => 5 [i] => 15 [s] => 16 
//[day_position] => 2 [week_of_the_month] => 4 )
Date Time difference
$dth->differenceAsObject($date);
//DateInterval Object ( [y] => 2 [m] => 3 [d] => 23 [h] => 7 [i] => 5 [s] => 6 
//[invert] => 1 [days] => 846 )

$dth->differenceAsWords('2011-03-01 10:00:10');
//about 2 years 3 months 23 days 7 hours 5 minutes 6 seconds ago
Repeat date time
$dth->nextRepeatDate($date, -5, 'i'); // 2011-03-01 10:05:10 < -5 minutes
$dth->nextRepeatDate($date, 5, 'i');  // 2011-03-01 10:15:10 < +5 minutes
$dth->nextRepeatDate($date, -5, 'h'); // 2011-03-01 05:10:10 < -5 hours
$dth->nextRepeatDate($date, 5, 'h');  // 2011-03-01 03:10:10 < +5 hours
$dth->nextRepeatDate($date, -5, 'd'); // 2011-02-24 10:10:10 < -5 days
$dth->nextRepeatDate($date, 5, 'd');  // 2011-03-06 10:10:10 < +5 days
$dth->nextRepeatDate($date, -5, 'w'); // 2011-01-25 10:10:10 < -5 weeks
$dth->nextRepeatDate($date, 5, 'w');  // 2011-04-05 10:10:10 < +5 weeks
$dth->nextRepeatDate($date, -5, 'm'); // 2010-10-01 10:10:10 < -5 months
$dth->nextRepeatDate($date, 5, 'm');  // 2011-08-01 10:10:10 < +5 months
$dth->nextRepeatDate($date, -5, 'y'); // 2006-03-01 10:10:10 < -5 years
$dth->nextRepeatDate($date, -5, 'y'); // 2016-03-01 10:10:10 < +5 years
Testing

- Download SimpleTest suit and place it to document root directory.
- Run unit_test.php
- Run date_time_helper.test.php or index.php

Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am ‘Added some feature’`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Something went wrong with that request. Please try again.