Skip to content

Instantly share code, notes, and snippets.

@davidthingsaker
davidthingsaker / time.php
Last active August 29, 2015 14:25
Human readable times in PHP
# Set a timestamp to time, e.g. 2 months
public static function time_ago($timestamp)
{
$years = floor($timestamp / 31536000);
$days = floor(($timestamp - ($years*31536000)) / 86400);
$hours = floor(($timestamp - ($years*31536000 + $days*86400)) / 3600);
$minutes = floor(($timestamp - ($years*31536000 + $days*86400 + $hours*3600)) / 60);
$timestring = '';
if ($years > 0){
$timestring .= $years . ' years ';