我正在尝试获取特定时间戳列的unix_timestamp值。但我很困惑。
$timecheck = mysql_query("SELECT UNIX_TIMESTAMP(datetime) FROM machine where m_id = $m_id");
if (mysql_num_rows($timecheck) > 0){
while ($timefetch = mysql_fetch_object($timecheck)) {
echo $timefetch->datetime;
print_r($timefetch[0]->datetime);
if (($timefetch->datetime - time()) > 6000){
echo "1";
}
else {
echo "0";
}
}
返回的时间戳值是stdClass对象。不能用它来比较。 有人可以帮我用下面的代码
答案 0 :(得分:4)
在SQL查询中使用列名的别名:
SELECT UNIX_TIMESTAMP(datetime) AS datetime FROM machine where m_id = $m_id