本文主要是介绍SqlServer查询本月第一天,上月最后一天,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
普通:
SELECT DATEADD(mm, DATEDIFF(m, 0, GETDATE()) - 1, 0) AS ‘上月第一天’,
DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, GETDATE()), 0)) AS ‘上月最后一天’,
DATEADD(mm, DATEDIFF(m, 0, GETDATE()), 0) AS ‘本月第一天’,
DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, GETDATE()) + 1, 0)) AS ‘本月最后一天’,
DATEADD(mm, DATEDIFF(m, 0, GETDATE()) + 1, 0) AS ‘下月第一天’,
DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, GETDATE()) + 2, 0)) AS ‘下月最后一天’
保留当前时分秒:
SELECTDATEADD(dd, 1 - DAY(DATEADD(mm, - 1, GETDATE())), DATEADD(mm, - 1, GETDATE())) AS ‘上月第一天’,
DATEADD(dd, - DAY(GETDATE()), GETDATE()) AS ‘上月最后一天’,
DATEADD(dd, 1 - DAY(GETDATE()), GETDATE()) AS ‘本月第一天’,
DATEADD(dd, - DAY(DATEADD(mm, 1, GETDATE())), DATEADD(mm, 1, GETDATE())) AS ‘本月最后一天’,
DATEADD(dd, 1 - DAY(DATEADD(mm, 1, GETDATE())), DATEADD(mm, 1, GETDATE())) AS ‘下月第一天’,
DATEADD(dd, - DAY(DATEADD(mm, 2, GETDATE())), DATEADD(mm, 2, GETDATE())) AS ‘下月最后一天’
作者:Hucxy
原文:https://blog.csdn.net/u013059149/article/details/79913692
这篇关于SqlServer查询本月第一天,上月最后一天的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!