【发布时间】:2014-03-21 19:48:59
【问题描述】:
使用 MySql
我有以下变量(以“3”和“2014”为例填写):
SET @Month = 3;
SET @Year = 2014;
期望的结果
I'd like to get the first day of the month and the last day of the month separately,
using the variables (avoiding any NOW() or CURDATE() formulas), in %Y-%m-%d format. In other words:
2014-03-01
2014-03-31
我已经尝试了以下基本函数的许多可能性,还有一些我已经删除了
SELECT LAST_DAY(`SELECT(@Year)-03-01`)
SELECT LAST_DAY('@Year-@Month')
SELECT DATE_FORMAT(?, '%Y-%m-01')
【问题讨论】:
-
SELECT STR_TO_DATE(CONCAT(@Year,'-',@Month,'-01'),'%Y-%m-%d'), LAST_DAY(STR_TO_DATE(CONCAT(@Year,'-',@Month,'-01'),'%Y-%m-%d')); -
是你要找的fiddle