tags:

views:

19

answers:

3

Hi, 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)

A: 

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

Col. Shrapnel
+3  A: 

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 |
+-----------+
Paul Dixon