I want to get difference in seconds between the current date and certain date which is stored in a database as DATETIME
type. I'm getting this date with this function:
function get_date_last_action($username)
{
$id = $this->get_username_id($username);
$query = "SELECT date_last_action".
"FROM user".
"WHERE user.id ='" . $id . "'";
$result = mysql_query($query);
$date_last_action = mysql_fetch_array($result);
return $date_last_action[0];
}
In a another code, I call this function:
$date = $h_db_functions->get_date_last_action("user1");
$currentTime = time();
$timeInPast = strtotime($date);
$differenceInSeconds = $currentTime - $timeInPast;
What's weird is that I'm getting a negative value.