PHP和MySQL的时间减少了几秒钟 [英] PHP and MySQL Subtract Seconds From Time

查看:118
本文介绍了PHP和MySQL的时间减少了几秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表中有2:00,我想从中减去0:01.在此之前,我曾在最近的一篇文章中尝试过,但这没有帮助.

I have 2:00 in a table and I would like to subtract 0:01 from it. I have tried in a recent post before this one, but it is no help.

在PHP和MySQL中,如何从2分钟中减去1秒?

In PHP and MySQL, how would I subtract 1 second from 2 minutes?

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

You can do it straight on the DB using 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()

Or you can get the time from MySQL and do it on PHP using DateTime::sub()

 // again from the manual
 <?php 
 $dateA = date_sub('2000-01-20', date_interval_create_from_date_string('1 second')); 
 ?> 

这篇关于PHP和MySQL的时间减少了几秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆