Creating a Variable of Present Date Minus a Past Timestamp
In the code below, "created" is a field in a MySQL table. This field is of the type "timestamp" and the d开发者_如何学运维efault is set to "CURRENT_TIMESTAMP" of whenever a given row is created.
In the query below, I would like to create a new variable that equals the present date minus the timestamp of "created", rounded off to units of days. I would like the present date to be whenever the query is run.
How could I do this?
Thanks in advance,
John
$sqlStr = "SELECT
l.loginid,
l.username,
l.created,
...
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
DATEDIFF(NOW(), l.created)
If you want 24-hour periods instead, you can use...
TIMESTAMPDIFF(HOUR, NOW(), l.created)
...and then divide by 24 and round or floor as you choose.
精彩评论