在这种情况下,我试图提取 - 从col2开始的第一天,记录201 - 从col2开始的星期几,记录201 - 从col2开始的前一个月的最后一天,记录201
我的代码:
SELECT DATEADD(month, DATEDIFF(month, 0, 1/19/2012), 0) AS StartOfMonth
FROM SpecialMenu
SELECT CONVERT(Varchar, Col2) FROM SpecialMenu
WHere col1 = 201
SELECT DATEADD(month, ((YEAR(@Year) - 2012) * 12) + MONTH(@Year), -1)
答案 0 :(得分:0)
declare @date datetime ='1/19/2012 08:00 AM'
SELECT DATEADD(month, DATEDIFF(month, 0, @date), 0) AS StartOfMonth ,
datepart(dw,@date) as dayofweek,
DATEADD(DAY, -(DAY(@date)), @date) lastdayofprevmonth