• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i have a relative time function into the codeigniter date helper (in the system folder). working like that of twitter t

While working on a codeigniter project with some friends i got to meet this problem of relative time. so i decided to develop one into the date helper that will ease to just auto load the date helper and then use it anywhere in my application i think i should give it back to the public. i think someone else might need it.
here are the codes, feel free to use it modify and redistribute it:

if ( ! function_exists('when'))
    function when($dt,$precision=2)

    $times=array(    365*24*60*60    => "year",
                    30*24*60*60        => "month",
                    7*24*60*60        => "week",
                    24*60*60        => "day",
                    60*60            => "hour",
                    60                => "minute",
                    1                => "second");


        $output='less than 5 seconds ago';
    }elseif($passed > 172800){
         $output=date("jS F,Y",$dt);

        foreach($times as $period=>$name)
            if($exit>=$precision || ($exit>0 && $period<60)) break;

            $result = floor($passed/$period);
                $output[]=$result.' '.$name.($result==1?'':'s');
            else if($exit>0) $exit++;

        $output=implode(', ',$output).' ago';

    return $output;

you can copy and paste these codes in the date_helper found in the system/helpers folder in your project, then auto upload the date helper in your autoload.php found in the application/config folder. at your database you should use any name to hold the datetime file should have typeSadint(11)) for it to work perfectly. from then things can how work well.
If any problem please do PM me.

Please i do apologize for posting here, i got mixed up i was to post this a the code and development section.
Thanks for your understanding

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.