View Single Post
  #4 (permalink)  
Old Dec 2nd, 2007, 09:23
c010depunkk's Avatar
c010depunkk c010depunkk is offline
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Some advaced stuff (I think)

How about writing it yourself... not at all hard...

1. convert the two dates into unix timestamps (time() function).
2. subtract timestamp1 from timestamp2.
3. convert to seconds into months/days/hours/min/sec. Here's a function I wrote for converting seconds (only hours/mins/secs):
PHP: Select all

function formatSecondsToString($num_sec) {
    if(
$num_sec<60) {
        return 
$num_sec.($num_sec==1?' second':' seconds');
    } else if(
$num_sec<3600) {
        
$m=floor($num_sec/60);
        
$s=$num_sec%60;
        return 
$m.($m==1?' minute':' minutes').($s==0?'':(' and '.$s.($s==1?' second':' seconds')));
    } else {
        
$h=floor($num_sec/3600);
        
$m=$num_sec%3600;
        
$s=$m%60;
        
$m=floor($m/60);
        return 
$h.($h==1?' hour':' hours').($m==0?'':(', '.$m.($m==1?' minute':' minutes'))).($s==0?'':(' and '.$s.($s==1?' second':' seconds')));
    }

Reply With Quote