Take the 2-minute tour ×

I have several dates in mysql tables, using those dates I need to find out the number of days in the month. Suppose i have 2003-02-05 it should return 28. for example

date                days_in_month
2003-2-3            28
share|improve this question

7 Answers 7

up vote 16 down vote accepted
share|improve this answer
Just beat me :) –  Cylindric May 24 '12 at 11:57

You can combine LAST_DAY with string function

SELECT RIGHT( LAST_DAY(  '2003-02-03' ) , 2 )
share|improve this answer

Try this:

SELECT DAYOFMONTH(LAST_DAY(your_date)) FROM your_table
share|improve this answer

An alternative to string-chopping is to use:

SELECT DAY(LAST_DAY('2010-02-1'));
share|improve this answer

Use following statement

share|improve this answer


select DAY(LAST_DAY(yourdate)) as days_in_month

share|improve this answer

I think you are asking the total number of days to be returned for a month. If you are trying to find the total number of days for current month, here is the query:

select timestampdiff(day,
date_add( concat(year(now()),'-',month(now()),'-01'), interval 1 month)).

If you want to externalize this using any programming language, externalize year and month in the code and replace that with now()

share|improve this answer

Your Answer

