I am new to sql and programming so please bear with me. Is there a function in mysql that gets the number of days in a month? Example if the month is February and the year 2012 it should return 29. Thanks in advance.
This might be what you are looking for. Show activity on this post. Go to the first day of the next month, and subtract one day. That gives you the total number of days for the current month.
There's no direct "last day of month", but you can fake it by doing a day(last_day())
mysql> select last_day('2012-02-22'), day(last_day('2012-02-22'));
+------------------------+-----------------------------+
| last_day('2012-02-22') | day(last_day('2012-02-22')) |
+------------------------+-----------------------------+
| 2012-02-29 | 29 |
+------------------------+-----------------------------+
1 row in set (0.00 sec)
last_day()
returns the full date of the last day in in the year/month of a specified date, so you then simply use day()
to extract the day of that last_day.
MySQL's date/time functions documentation is here: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With