I have been trying to get this code working properly - basically I would like to display the time elapsed since and article was posted by subtracting it from the current time. I have almost got it, I found this code below and all works well except for the minutes and seconds. I can figure out why its not showing the seconds or minutes if applicable. Just to clear each article shows the applicable elapsed time so if < 60s it should show howmany seconds, > then should show minutes etc
my code is
<?php
$today = time();
$post = $item->created;
$createdday= strtotime($post); //convert $post to unix timestamp
$datediff = abs($today - $createdday);
$difftext="";
$years = floor($datediff / (365*60*60*24));
$months = floor(($datediff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($datediff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$hours= floor($datediff/3600);
$minutes= floor($datediff/60);
$seconds= floor($datediff);
//year checker
if($difftext=="")
{
if($years>1)
$difftext=$years." years ago";
elseif($years==1)
$difftext=$years." year ago";
}
//month checker
if($difftext=="")
{
if($months>1)
$difftext=$months." months ago";
elseif($months==1)
$difftext=$months." month ago";
}
//month checker
if($difftext=="")
{
if($days>1)
$difftext=$days." days ago";
elseif($days==1)
$difftext=$days." day ago";
}
//hour checker
if($difftext=="")
{
if($hours>1)
$difftext=$hours." hours ago";
elseif($hours==1)
$difftext=$hours." hour ago";
}
//minutes checker
if($difftext=="")
{
if($minutes>1)
$difftext=$minutes." minutes ago";
elseif($minutes==1)
$difftext=$minutes." minute ago";
}
//seconds checker
if($difftext=="")
{
if($seconds>1)
$difftext=$seconds." seconds ago";
elseif($seconds==1)
$difftext=$seconds." second ago";
}
echo " <span class=timediff> | ".$difftext . "</span>"; ?>
and my example is here http://www.landnsand.co.za/dev/test/ the latest reading module below the slides.
Any suggestions or advise as to why the seconds and minutes may not be working would be greatly appreciated! I have searched high and low and have tried alot of options but must be missing something.
With Thanks