Here's a function I found by searching:
function calcDateDiff($date1, $date2) {
if( $date2 > $date1 ) {
$tmp = $date2;
$date2 = $date1;
$date1 = $tmp;
}
$diff = $date1-$date2;
$seconds = 0;
$hours = 0;
$minutes = 0;
if($diff % 86400 <= 0) //there are 86,400 seconds in a day
$days = $diff / 86400;
if($diff % 86400 > 0) {
$rest = ($diff % 86400);
$days = ($diff - $rest) / 86400;
if( $rest % 3600 > 0 ) {
$rest1 = ($rest % 3600);
$hours = ($rest - $rest1) / 3600;
if( $rest1 % 60 > 0 ) {
$rest2 = ($rest1 % 60);
$minutes = ($rest1 - $rest2) / 60;
$seconds = $rest2;
} else
$minutes = $rest1 / 60;
} else
$hours = $rest / 3600;
}
return "$days days, $hours hours, $minutes minutes, and $seconds seconds";
}
EDIT: Woops, hit submit too soon.
This function works with two Unix timestamps. To convert your database's DATETIME field into a Unix timestamp, you can use the MySQL function UNIX_TIMESTAMP(). Then, you'd use the [man]time/man function (instead of your date() call) to get the current timestamp.
Also note that doing "SELECT *" almost always wastes resources as you're selecting more columns that you actually need. Try just selecting the column(s) you're going to use.