Hi,
I'm seeking an elegant solution to change the format of time based on the length of time between now, and a ISO formated date in a DB.
I'd like the output to look something like this
//less than an hour
'X minutes have gone by'
//less than 24 hours
'X hours have gone by'
//greater than 24 hours
ISO date
Here is what I have so far...
$now = date("o-m-d H:i:s") //now = something like '2009-12-28 16:39:00'
$dateExample = '2009-12 16:37:00'
$timeSpan = round(strtotime($now) - strtotime($dateExample));
if(($timeSpan/60)<=60)
{
echo $timeSpan." minutes";
}
if(($timeSpan/(60*60))<=24)
{
echo ($timeSpan/(60*60))." Hours";
}
else
{
echo $dateExample;
}
The sloppy if statements are really bothering me and I can't seem to figure out a better way to do it....