首页 > 代码库 > sql server 小笔记1

sql server 小笔记1

DECLARE @CurrentDate DATETIME=GETDATE();

select
DATEADD(dd,0, DATEDIFF(dd,0,@CurrentDate)) AS 当前日期,
DATEADD(dd,-1, DATEDIFF(dd,0,@CurrentDate)) AS 昨天,
DATEADD(MM,DATEDIFF(MM,0,@CurrentDate),0) AS 本月第一日,
DATEADD(DAY,-1,DATEADD(MM,DATEDIFF(MM,0,@CurrentDate)+1,0)) 本月最后一日,
DATEADD(mm,DATEDIFF(mm,0,dateadd(month,-1,@CurrentDate)),0) AS 上月第一日,
dateadd(d,-1,dateadd(m,-1,DATEADD(mm, DATEDIFF(m,0,@CurrentDate)+1, 0))) AS 上月最后一日

sql server 小笔记1