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

--前四个月

 

posted on 2017-01-05 17:01  Lucy Yang  阅读(134)  评论(0编辑  收藏  举报

导航