sqlserver 取取月初月末和月份间隔

开发中常用到的,记录下来,提供给需要参考的朋友!

 


--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)

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...