0

I have statistics that require a 'Last Updated' section on a dynamic image, and is expressed in hours. This is done with the following:

$lastDate = $StatData->date;
$now = date("Y-m-d G:i:s");
$hours = (strtotime($now) - strtotime($lastDate)) / 3600;

Displaying $hours on the image with an imagettftext works just fine. It's just that it's up to 16 characters in length. So to fix that, I attempted the following:

if($hours < 10) {
    substr($hours,0,4);
} else {
    substr($hours,0,5);
}

The intention was to display no more than two decimals. The result was no change. As if the code wasn't even there.

So my question is one of two: 1: How do i get this to work? 2: I know there is a way to limit the decimal places, without using substr, but what is it? Might be a better solution.

4

2 に答える 2