php - Getting time eg 5 minutes ago -


this question has answer here:

i have added timestamp database have exact time post made , '5 minutes ago' or long has been.

is there php method or or how it?

thanks

there no native function this, have write script... works me:

php

function elapsedtime($time_since) {     $time = time() - $time_since;     $tokens = array (         31536000 => 'year',         2592000 => 'month',         604800 => 'week',         86400 => 'day',         3600 => 'hour',         60 => 'minute',         1 => 'second'     );     foreach ($tokens $unit => $text) {         if ($time < $unit) continue;             $numberofunits = floor($time / $unit);             return $numberofunits.' '.$text.(($numberofunits>1)?'s':'');         }     } } 

html

<div class="answertime">     asked <?= elapsedtime($time_since) /* time variable */ ?> ago </div> 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -