SqlServer 獲取本週、本月、本季、本年的第一天和最後一天
阿新 • • 發佈:2019-02-03
--本週
select dateadd(WEEK, datediff(WEEK, 0, getdate()), 0);
select dateadd(WEEK, datediff(WEEK, 0, getdate()), 7);
--本月
select dateadd(month, datediff(month, 0, getdate()), 0);
select dateadd(month, datediff(month, -1, getdate()), -1);
--本季
select dateadd(QUARTER , datediff(QUARTER ,0, getdate()), 0);
select dateadd(QUARTER , datediff(QUARTER , -1, getdate()), -1);
--本年
select dateadd(year, datediff(year, 0, getdate()), 0);
select dateadd(year, datediff(year, -1, getdate()), -1);
這回全了,Oracle和SqlServer的都有了