October 26 2013

Mysql last day of the month

Tagged Under : ,

MySQL
Because sometimes need to know last day of the previous month, and I was using procedure/routine to completed the query. That’s the reason I can’t use others programming language to do it. All the thing must finish in MySQL server only.

And very lucky, MySQL have “last_day()” function to get last day of the month.

Below example are showing how to use it.
select last_day(now());
It will return current month last day.

You also allow specific a day as well. and it will return “2013-02-28“;
select last_day("2013-02-15");

To get last month last of the day. you can do like this.
select last_day(curdate() - interval 1 month);

Make a Comment

You must be logged in to post a comment.