PHP Classes

A DateTime Helper: Get the difference between times in English

Recommend this page to a friend!
  Info   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (8 months ago) RSS 2.0 feedStarStarStarStar 74%Total: 472 All time: 6,010 This week: 60Up
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
Age: 44
All time rank: 175324 in Bangladesh Bangladesh
Week rank: 178 Up3 in Bangladesh Bangladesh Up

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 (1)  
  • screenshot.png
  Files folder image Files (6)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:472
This week:0
All time:6,010
This week:60Up
User Ratings User Comments (1)
 All time
Utility:83%StarStarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:83%StarStarStarStarStar
Examples:83%StarStarStarStarStar
Tests:83%StarStarStarStarStar
Videos:-
Overall:74%StarStarStarStar
Rank:82
 
Nice package
11 years ago (Morshed ALam)
90%StarStarStarStarStar