开发中常用到的,记录下来,提供给需要参考的朋友!
--1.取月初月末
declare @startdate datetime
select @startdate=dateadd(dd,-datepart(dd,getdate())+1,getdate())
select SUBSTRING(Convert(varchar(100),@startdate,23),1,10)
declare @enddate datetime
select @enddate=dateadd(dd,getdate()),dateadd(mm,getdate()))
select SUBSTRING(Convert(varchar(100),@enddate,10)
--2.取间隔一个月
declare @startdate datetime
select @startdate= dateadd(MM,-1,dateadd(dd,getdate()))
select SUBSTRING(Convert(varchar(100),10)
declare @enddate datetime
select @enddate=dateadd(MM,getdate())))
select SUBSTRING(Convert(varchar(100),10)