How can I select how many days old a field is based on it's "DateAdded" field?
E.g.:
SELECT DAYSOLD(tbl_stuff.DateAdded) as DaysOld
FROM tbl_stuff
Use:
SELECT DATEDIFF(NOW(), ts.dateadded) AS daysold
FROM TBL_STUFF ts
Reference: DATEDIFF
DATEDIFF() returns expr1 – expr2 expressed as a value in days from one date to the other.
You can use the DATEDIFF
function, to get the difference, in days, between tbl_stuff.DateAdded
and curdate()
.
For example :
mysql> select datediff(curdate(), '2010-03-15') as daysOld;
+---------+
| daysOld |
+---------+
| 8 |
+---------+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With