Use php and MySQL, I want to get the duration in php code between time obtained by get_date() function and time stored in table by NOW() sql function. How to do this? Help me please.
使用php和MySQL,我希望在get_date()函数获得的时间和NOW()sql函数存储在表中的时间之间获取php代码的持续时间。这个怎么做?请帮帮我。
2 个解决方案
#1
1
This might work:
这可能有效:
$result = mysql_query("SELECT UNIX_TIMESTAMP() - " . time() . " AS diff");
$result = mysql_fetch_array($result);
$diff = $result['diff'];
$diff
will contain the difference in seconds between the mysql server and the webserver
$ diff将包含mysql服务器和Web服务器之间的秒数差异
Edit: to get the HH:MM:SS difference
编辑:获得HH:MM:SS差异
$result = mysql_query("SELECT TIMEDIFF(UNIX_TIMESTAMP(), " . time() . ") AS diff");
#2
1
Mysql dates will return as strings in the format 'YYYY-MM-DD HH:II:SS'. Use the strtotime($date_from_db) to convert it to PHP date. If you're getting the current date/time do not use the getdate() function go for now() instead. After that, use the same instruction from the link PHP How to find the time elapsed since a date time? .
Mysql日期将以“YYYY-MM-DD HH:II:SS”格式返回为字符串。使用strtotime($ date_from_db)将其转换为PHP日期。如果您正在获取当前日期/时间,请不要使用getdate()函数来改为now()。之后,使用链接PHP中的相同指令如何查找自日期时间以来经过的时间? 。
#1
1
This might work:
这可能有效:
$result = mysql_query("SELECT UNIX_TIMESTAMP() - " . time() . " AS diff");
$result = mysql_fetch_array($result);
$diff = $result['diff'];
$diff
will contain the difference in seconds between the mysql server and the webserver
$ diff将包含mysql服务器和Web服务器之间的秒数差异
Edit: to get the HH:MM:SS difference
编辑:获得HH:MM:SS差异
$result = mysql_query("SELECT TIMEDIFF(UNIX_TIMESTAMP(), " . time() . ") AS diff");
#2
1
Mysql dates will return as strings in the format 'YYYY-MM-DD HH:II:SS'. Use the strtotime($date_from_db) to convert it to PHP date. If you're getting the current date/time do not use the getdate() function go for now() instead. After that, use the same instruction from the link PHP How to find the time elapsed since a date time? .
Mysql日期将以“YYYY-MM-DD HH:II:SS”格式返回为字符串。使用strtotime($ date_from_db)将其转换为PHP日期。如果您正在获取当前日期/时间,请不要使用getdate()函数来改为now()。之后,使用链接PHP中的相同指令如何查找自日期时间以来经过的时间? 。