Reputation: 7109
How to calculate the number of difference between a specific date to the current year last date. Consider I would like to show date difference between 2009-09-01 to current year last date(2010-12-31)
Upvotes: 0
Views: 3029
Reputation: 300825
Use to_days
:
select to_days(concat(year(now()),'-12-31')) - to_days(now()) as days_left;
+-----------+
| days_left |
+-----------+
| 121 |
+-----------+
or use datediff like this
select datediff(concat(year(now()),'-12-31'), now()) as days_left;
+-----------+
| days_left |
+-----------+
| 121 |
+-----------+
Upvotes: 5
Reputation: 157839
mysql have a function for everything.
One you need in this particular case is TO_DAYS()
Upvotes: 0
Reputation: 25370
use datediff function:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff
Upvotes: 1