Hi all,
I have two dates:
1 = $last_check = YYYY-MM-DD HH:MM:SS (A SQL value)
2 = $datetime = YYYY-MM-DD HH:MM:SS (Called using PHP)
How can I take away 1 from 2 and convert the minutes and seconds left over into seconds?
Basically I'm running an uptime counter script that will cycle through about 1000 servers. What I'm going to do is get the number of seconds since it was last checked, and if its online add them to the uptime counter in SQL and if its offline add them to the downtime counter in SQL.
It will be never be more than a few minute since the last check.
Should I use something like explode or is there a cleaner way of doing this? :
$last_check_query = mysql_query("SELECT last_check from servers_updowntime where serverid = ".$serv_id."");
$last_check = mysql_fetch_array($last_check_query);
$time_since_last_check = (date("Y-m-d H:i:s") - $last_check[0]);
$hms = ($time_since_last_check - date("Y-m-d H:i:s"));
function time2seconds($time='00:00:00')
{
list($hours, $mins, $secs) = explode(':', $time);
return ($hours * 3600 ) + ($mins * 60 ) + $secs;
}