我在桌子上有2点,我想从中减去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());
}
}
感谢。
答案 0 :(得分:5)
您可以使用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获得时间并使用DateTime::sub()
// again from the manual
<?php
$dateA = date_sub('2000-01-20', date_interval_create_from_date_string('1 second'));
?>
答案 1 :(得分:0)
检查
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html用于MySQL函数,
PHP的答案 2 :(得分:0)
答案 3 :(得分:0)
使用您提供的内容检查此代码的php风格 -
<?php
$t1= '0:2:00';
$t2= '0:0:01';
$a1 = explode(":",$t1);
$a2 = explode(":",$t2);
$time1 = (($a1[0]*60*60)+($a1[1]*60)+($a1[2]));
$time2 = (($a2[0]*60*60)+($a2[1]*60)+($a2[2]));
$diff = abs($time1-$time2);
$hours = floor($diff/(60*60));
$mins = floor(($diff-($hours*60*60))/(60));
$secs = floor(($diff-(($hours*60*60)+($mins*60))));
$result = $hours.":".$mins.":".$secs;
echo $result;