0

Possible Duplicate:
Calculate DateDiff in SQL in Days:Hours:Mins:Seconds format

I have this MySql query:

SELECT DATEDIFF(MAX(hit_date), MIN(hit_date)) / (COUNT(hit_date) - 1) AS hitavg FROM my_table

This returns a value (average days between recorded rows from hit_date column, this column is in TIMESTAMP format, so YY:MM:DD HH:MM:SS)

Assuming that this value is 385.500 (returned from the query), how can I format in PHP this number as 385 Days, "n" Hours (where "n" is the decimal value, in this case 500)?

Thanks in advance to all!

Community
  • 1
  • 1
David Madhatter
  • 285
  • 2
  • 6
  • 13

1 Answers1

2

Well, if you only want Days and Hours, then:

$value = 385.500;

$days = (int) $value;
$hours = 24 * ($value - $days);

echo "$days Days, $hours Hours";
crush
  • 16,713
  • 9
  • 59
  • 100
  • I replaced `floor()` with `(int)` because casting to int is 2x faster than calling `floor()` and achieves the same result. – crush Jan 23 '13 at 21:42