Reputation: 2036
How to get last day of the month in MySQL by providing month and year as input.
Similar example, To get last day of the month by date as input
Eg: SELECT LAST_DAY(?) as lastDate
Format:
Input month and year: '07/2015'
Output Result: day /*Eg: 30,31*/
I have tried with date Format
SELECT LAST_DAY(DATE_FORMAT('09/2015','%m/%Y')) as lastDate
but it din't work
Upvotes: 6
Views: 12757
Reputation: 1
SELECT DATE_FORMAT(LAST_DAY('2015-9-1'),'%d')
just add an any number date (day) in the query, and then get last day only using date format %d
Upvotes: 0
Reputation: 13700
set @year:=2010;
set @month:=10;
select last_day(concat(@year,'-',@month,'-01')) as last_day;
Upvotes: 3
Reputation: 1269573
You just need to convert your values to a date. Here is one way:
select last_day(date(concat_ws('-', year, month, 1)))
Upvotes: 6