SQL 篩選日期語法

–今天

Select * From TableName Where DateDiff(dd, DateTimCol, GetDate()) = 0

–昨天

Select * From TableName Where DateDiff(dd,DateTimCol, GetDate()) = 1

–明天

Select * From TableName Where DateDiff(dd,GetDate(),DateTimCol ) = 1

–最近七天

Select * From TableName Where DateDiff(dd, DateTimCol, GetDate()) <= 7

–隨後七天

Select * From TableName Where DateDiff(dd,,GetDate(),DateTimCol ) <= 7

–上週

Select * From TableName Where DateDiff(wk, DateTimCol, GetDate()) = 1

–本週

Select * From TableName Where DateDiff(wk, DateTimCol, GetDate()) = 0

–下週

Select * From TableName Where DateDiff(wk,GetDate(),DateTimCol,) = 1

–上月

Select * From TableName Where DateDiff(mm, DateTimCol, GetDate()) = 1

–本月

Select * From TableName Where DateDiff(mm, DateTimCol, GetDate()) = 0

–下月

Select * From TableName Where DateDiff(mm, GetDate(),DateTimCol ) = 1