Aadi
Aadi

Reputation: 7109

calculate number of days left in an year from specific date using mysql

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

Answers (3)

Paul Dixon
Paul Dixon

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

Your Common Sense
Your Common Sense

Reputation: 157839

mysql have a function for everything.
One you need in this particular case is TO_DAYS()

Upvotes: 0

Related Questions