用字符串MYSQL设置日期

时间:2019-06-18 08:40:25

标签: mysql

我想和字符串约会,但是字符串连接有问题,我可以这样做:

@MyVariable ='1'+ ' '+@month +' '+year(now)

但这是行不通的,所以我试图使用类似的东西:

CAST(year(now()) as CHAR(4))

但是总是相同的问题。这是一个真正的问题,因为我无法使用STR_TO_DATE函数。

我的SQL查询:

SET @Month = month(TIMESTAMPADD(month, -1, CAST(now() as DATE)));
Set @firstDay = STR_TO_DATE('1'+ ' '+@month +' '+year(now),"%d %M %Y");
SET @lastDay = last_day(TIMESTAMPADD(month, -1, CAST(now() as DATE)));
SELECT count(*) AS M1 FROM DATE where CAST(DATE_CREATION as DATE) 
BETWEEN @firstDay and @lastDay;

感谢阅读!

0 个答案:

没有答案