答案 0 :(得分:2)
您可以使用EOMONTH代替核心值1
:
select dateadd(day, 1, eomonth(date, -1))
from table t;
答案 1 :(得分:0)
--You can Use the YEAR and MONTH functions and cast them
--to varchar and concat them together with '01' as the day on the end
--with CASE on month in case it is single digit month, prepend zero
SELECT CAST(YEAR([Date]) AS varchar(10)) + CASE WHEN MONTH([Date]) < 10 THEN '0' + CAST(MONTH([Date]) AS varchar(2)) ELSE CAST(MONTH([Date]) AS varchar(2)) END + '01' AS [HardCodedDate]
FROM [Table]
答案 2 :(得分:0)
DATEDIFF
和DATEADD
方法在这里也适用:
DATEADD(MONTH,DATEDIFF(MONTH,0,[date]),0)