Post Reply  Post Thread 
PHP script for Duration Calculator
Author Message
admin
~CM~
*******


Posts: 147
Group: Administrators
Joined: Jul 2007
Status: Offline
Reputation: 0
Thank 0
2 was given thank in 2 posts
Post: #1
PHP script for Duration Calculator

This is function to calculate duration between 2 date/time given.

Function :

PHP Code:
function Duration($s$e){ 
     
    
/* Find out the seconds between each dates */ 
    
$timestamp $e $s
     
    
/* Cleaver Maths! */ 
    
$years=floor($timestamp/(60*60*24*365));$timestamp%=60*60*24*365
    
$weeks=floor($timestamp/(60*60*24*7));$timestamp%=60*60*24*7
    
$days=floor($timestamp/(60*60*24));$timestamp%=60*60*24
    
$hrs=floor($timestamp/(60*60));$timestamp%=60*60
    
$mins=floor($timestamp/60);$secs=$timestamp%60
    
    
/* Display for date, can be modified more to take the S off */ 
    
if ($years >= 1) { $str.= $years.' years '; } 
    if (
$weeks >= 1) { $str.= $weeks.' weeks '; } 
    if (
$days >= 1) { $str.=$days.' days '; } 
    if (
$hrs >= 1) { $str.=$hrs.' hours '; } 
    if (
$mins >= 1) { $str.=$mins.' minutes '; } 
    
     return 
$str
         


Example Usage :

PHP Code:
$s mktime(930007151990); 

    list(
$year,$month,$day,$hour,$minute,$second) = split('[:-]' ,date('Y-m-d H:i:s')); 
    
$e mktime($hour$minute$second$month$day$year); 

    echo 
Duration($s$e); 


Thanks & Regards
------------------
~CM~

ADD TO DEL.ICIO.US  ADD TO DIGG  ADD TO FURL  ADD TO NEWSVINE  ADD TO NETSCAPE 
ADD TO TECHNORATI FAVORITES  Technorati ADD TO SQUIDOO  ADD TO WINDOWS LIVE  ADD TO YAHOO MYWEB  ADD TO ASK 
ADD TO REDDIT  ADD TO STUMBLEUPON  ADD TO GOOGLE   

07-15-2007 03:23 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  PHP Script to parse /etc/passwd and how to use the new __get magic method (PHP5) admin 0 452 07-19-2007 03:46 PM
Last Post: admin
  Simple php script for site visitor counter admin 0 367 07-18-2007 07:19 PM
Last Post: admin
  PHP script to find difference between server time and local time admin 0 463 07-18-2007 04:36 AM
Last Post: admin
  GD test script Nilesh 0 716 07-15-2007 09:31 AM
Last Post: Nilesh
  Zend Optimizer test script Nilesh 0 1,214 07-15-2007 09:22 AM
Last Post: Nilesh
  How to Send Email from a PHP Script Using SMTP Authentication Nilesh 0 4,035 07-15-2007 09:17 AM
Last Post: Nilesh
  PHP script for backup of mysql database admin 0 583 07-15-2007 03:33 AM
Last Post: admin

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: