我在表中有 2:00,我想从中减去 0:01。我在这篇文章之前的最近一篇文章中尝试过,但没有帮助。
在 PHP 和 MySQL 中,如何将 2 分钟减去 1 秒?
if (isset($_GET['id']) && isset($_GET['time'])) {
mysql_select_db("aleckaza_pennyauction", $connection);
$query = "SELECT Current_Time FROM Live_Auctions WHERE ID='1'";
$results = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($results)) {
$newTime = $row['Current_Time'];
$query = "INSERT INTO Live_Auctions(Current_Time) VALUES('".$newTime."')";
$results = mysql_query($query) or die(mysql_error());
}
}
谢谢。
最佳答案
您可以使用 MySQL 在数据库上直接执行此操作 SUBTIME()
// from the manual
mysql> SELECT SUBTIME('2007-12-31 23:59:59.999999','1 1:1:1.000002');
-> '2007-12-30 22:58:58.999997'
或者您可以从 MySQL 获取时间并在 PHP 上使用 DateTime::sub()
执行此操作
// again from the manual
<?php
$dateA = date_sub('2000-01-20', date_interval_create_from_date_string('1 second'));
?>
关于PHP 和 MySQL 从时间中减去秒数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12720064/