The development of commonly used, recorded down, provided to the need for reference friends!
--1 at the end of the month.
DECLARE @startdate datetime
Select @startdate =dateadd (Dd,-datepart (Dd,getdate ()) +1,getdate ())
Select SUBSTRING (Convert (varchar, @startdate, 23), 1,10)
DECLARE @enddate datetime
Select @enddate =dateadd (Dd,-datepart (Dd,getdate ()), DateAdd (Mm,1,getdate ())
Select SUBSTRING (Convert (varchar, @enddate, 23), 1,10)
--2. Take one months interval
DECLARE @startdate datetime
Select @startdate = DATEADD (Mm,-1,dateadd (dd,-datepart (dd,getdate ()) +1,getdate ())
Select SUBSTRING (Convert (varchar, @startdate, 23), 1,10)
DECLARE @enddate datetime
Select @enddate =dateadd (MM, -1,dateadd (Dd,-datepart (Dd,getdate ()) +1,dateadd (Mm,1,getdate ()))
Select SUBSTRING (Convert (varchar, @enddate, 23), 1,10)
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/SQLServer/