开发者

Mysql/Php - Current date and time

I have a query that I want to update a column with the current date time. The column I want to update is of the type datetime.

How can I get it and set it?

else{ //If the last update is NULL, It must be players first page load. So set datetime eq开发者_如何学运维ual to NOW
    $query = "UPDATE `stats` SET `last_ap_update` =    WHERE `member_id` = {$_SESSION['SESS_MEMBER_ID']}"; 
    $queryresult = mysql_query($insertqry);
}


Using NOW() in the query would provide this.

else{ //If the last update is NULL, It must be players first page load. So set datetime equal to NOW
    $query = "UPDATE `stats` SET `last_ap_update` =  NOW()  WHERE `member_id` = {$_SESSION['SESS_MEMBER_ID']}"; 
    $queryresult = mysql_query($insertqry);
}

But if this gets updated anytime the table updates, I would suggest changing the column to TIMESTAMP and this will automatically update to the current time for you anytime that record changes.


else{ //If the last update is NULL, It must be players first page load. So set datetime equal to NOW
    $query = "UPDATE `stats` SET `last_ap_update` =  '".gmdate("Y-m-d H:i:s")."'  WHERE `member_id` = {$_SESSION['SESS_MEMBER_ID']}"; 
    $queryresult = mysql_query($insertqry);
}

You can use any format you want instead of gmdate("Y-m-d H:i:s")


You can use the mysql function NOW() for this, or you can pase the $_SERVER['REQUEST_TIME'] in there so the query gets cached by mysql.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜