从mysql时间格式到现在的秒数

I use this function to set a time date("Y-m-d H:i:s", strtotime("+2 minutes"). Now I want to compare that value with the current time to find the amount of seconds it's left.

For example compare: $next_action = 2011-01-16 18:03:00 and $now = 2011-01-16 18:01:23. To find the amount of seconds.

strtotime can convert mysql timestamps to unix timestamps. so you just convert both of them to UNIX timestamps and subtract one from other, and you'll get the difference in seconds.

$next_action = "2011-01-16 18:03:00";
$now = "2011-01-16 18:01:23";

echo strtotime($next_action)-strtotime($now);

Why did you convert them to "Y-m-d H:i:s" in the first place? Unix timestamps are much easier to work with.

$start_time = date("Y-m-d H:i:s", strtotime("+2 minutes"));
$time_diff = (time() - strtotime($start_time)); // difference in seconds

$seconds = $time_diff % 60;
$minutes = ($time_diff - $seconds) % (60 * 60);
$hours = ($time_diff - ($minutes * 60) - $seconds) / (24 * 60 * 60);

Untested, but it would probably go something like this.