tags:

views:

46

answers:

1

Hello,

In the code below, "created" is a field in a MySQL table. This field is of the type "timestamp" and the default 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,
    ...
+2  A: 

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.

Amber
Thanks... you're cool.
John