Sql Server 日期查询

当前月:

USE [DBName]

Go

Use Database, Declare Variables

DECLARE @ReportGenerationDate DATE

DECLARE @ReportMonth   INT

DECLARE @ReportMonthStart  DATE

DECLARE @ReportMonthEnd   DATE

SET @ReportGenerationDate = GETDATE()

SET @ReportMonth  = MONTH(@ReportGenerationDate) - 1

SET @ReportMonthEnd  = DATEADD(DAY, DATEPART(d, @ReportGenerationDate)*-1 , @ReportGenerationDate)

SET @ReportMonthStart = DATEADD(MONTH, -1, DATEADD(DAY, 1, @ReportMonthEnd))

print @ReportMonthStart

print @ReportMonthEnd

--前四个月

转载于:https://www.cnblogs.com/tutuyforever/p/6253107.html

猜你喜欢

转载自blog.csdn.net/weixin_33814685/article/details/94682057