如何通过输入月份和年份来获取mysql中月份的最后一天 [英] How to get last day of month in mysql by giving month and year as input

查看:39
本文介绍了如何通过输入月份和年份来获取mysql中月份的最后一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过提供月份和年份作为输入来获取MySQL中的月份的最后一天.

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*/

我尝试使用日期格式选择LAST_DAY(DATE_FORMAT('09/2015','%m/%Y'))作为lastDate ,但无效

推荐答案

您只需要将值转换为日期即可.这是一种方法:

You just need to convert your values to a date. Here is one way:

select last_day(date(concat_ws('-', year, month, 1)))

这篇关于如何通过输入月份和年份来获取mysql中月份的最后一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆