MySQL The choice of the number of days "Days".

How can I choose how many days a field has passed based on the DateAdded field?

eg:.

SELECT DAYSOLD(tbl_stuff.DateAdded) as DaysOld FROM tbl_stuff 
+4
source share
3 answers

Using:

 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 another.

+5
source

You can use the DATEDIFF function to get the difference between days between tbl_stuff.DateAdded and curdate() .


For instance:

 mysql> select datediff(curdate(), '2010-03-15') as daysOld; +---------+ | daysOld | +---------+ | 8 | +---------+ 
+2
source

You can use to_days() or datediff() functions.

MySQL has many date functions, you can directly link there http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html .

+1
source

Source: https://habr.com/ru/post/1304840/


All Articles