Mysql/Php-当前日期和时间 [英] Mysql/Php - Current date and time

查看:71
本文介绍了Mysql/Php-当前日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询,我想用当前日期时间更新一列.我要更新的列的类型为datetime.

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.

如何获取并设置?

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` =    WHERE `member_id` = {$_SESSION['SESS_MEMBER_ID']}"; 
    $queryresult = mysql_query($insertqry);
}

推荐答案

在查询中使用NOW()将提供此功能.

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);
}

但是,如果在表更新的任何时候对此进行更新,我建议将列更改为TIMESTAMP,并且它将在记录更改的任何时候为您自动更新为当前时间.

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.

这篇关于Mysql/Php-当前日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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