如何将当前服务器时间与SQL数据库时间戳进行比较?

时间:2015-04-18 09:30:04

标签: php mysql

我想将当前时间与数据库中的预定义时间戳范围(start_time和end_time)进行比较。但查询没有返回任何内容。将会感激任何帮助。

    public function setCurrentGw()  //Isn't allowed to set externally
    {
        $this->table='gameweek';
        $current_time = new time();

        $query="SELECT `gw`,`start_time`,`end_time` FROM `$this->table` WHERE `start_time`<=$current_time AND $current_time<=`end_time`";

        if($q=mysql_query($query))
        {
            $temp=mysql_fetch_assoc($q);
            $this->current_gw=$temp['gw'];
            echo $temp['start_time'];
            echo 'Current#'.$this->current_gw.'<br/>';
        }
        else
        {
            echo 'Technical Failure! Try Again';
        }
    }

1 个答案:

答案 0 :(得分:0)

OP宣称NOW()有效。

相关问题