PHP Classes

A DateTime Helper: Get the difference between times in English

Recommend this page to a friend!
  Info   Screenshots Screenshots   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (4 days ago) RSS 2.0 feedNot enough user ratingsTotal: 470 This week: 1All time: 6,011 This week: 348Up
Version License PHP version Categories
date-time-helper 1.1.0The PHP License5.0PHP 5, Time and Date
Description 

Author

This class can get the difference between times in English.

It can compare two timestamps and return the difference spelled with English words or an an object.

Time details either as an array or an object.

The class can also return a new time adding time intervals in days, week, month, etc..

Picture of Morshed Alam
  Performance   Level  
Name: Morshed Alam <contact>
Classes: 2 packages by
Country: Bangladesh Bangladesh

Details

h3. 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":http://www.scripts.morshed-alam.com/date_time_helper/ :: "Try it out and Rate on phpclasses.org":http://www.phpclasses.org/package/7807-PHP-Get-the-difference-between-times-in-English.html h6. Uses <pre> require 'date_time_helper.php'; // Instance of DateTime helper class // By default helper class work with current date time $dth = new DateTimeHelper(); </pre> h6. Date Time parts <pre> $dth->year(); $dth->month(); $dth->day(); $dth->hours(); $dth->minutes(); $dth->seconds(); //2013, 6, 24, 4, 51, 3 </pre> h6. DateTime details as an object <pre> $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 ) </pre> h6. Date Time difference <pre> $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 </pre> h6. Repeat date time <pre> $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 </pre> h6. Testing - Download "SimpleTest":http://www.simpletest.org/en/download.html suit and place it to document root directory. - Run unit_test.php - Run date_time_helper.test.php or index.php h6. 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

Screenshots  
  • screenshot.png
  Files folder image Files  
File Role Description
Plain text file date_time_helper.php Class Class source
Accessible without login Plain text file date_time_helper.test.php Example Example script
Accessible without login Plain text file index.php Example Test feature
Accessible without login Plain text file README.textile Doc. Documentation
Accessible without login Plain text file unit_test.php Test Unit test script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:470
This week:1
All time:6,011
This week:348Up
User Comments (1)
Nice package
11 years ago (Morshed ALam)
90%StarStarStarStarStar