As per this topic on Oracle relative dates, here’s the same set of dates in SQL Server.
Please note that some may not work on SQL Server 2000, but all definitely work in 2005/8.
Yesterday
cast(convert(char(10),dateadd(d,-1,getdate()),23) as datetime)
Today
cast(convert(char(10),getdate(),23) as datetime)
The following also works for today:
dateadd(dd, datediff(dd,0,getdate()), 0)
Start of Current Month
cast(convert(char(7),getdate(),23)+'-01' as datetime)
End of Current Month
dateadd(d,-1,dateadd(m,1,cast(convert(char(7),getdate(),23)+'-01' as datetime)))
Start of Previous Month
dateadd(m,-1,cast(convert(char(7),getdate(),23)+'-01' as datetime))
End of Previous Month
dateadd(d,-1,cast(convert(char(7),getdate(),23)+'-01' as datetime))
Start of Current Quarter
dateadd(qq,datediff(qq,0,getdate()),0)
End of Current Quarter
dateadd(qq,datediff(qq,-1,getdate()),-1)
Start of Previous Quarter
dateadd(qq,datediff(qq,2,getdate()),0)
End of Previous Quarter
dateadd(qq,datediff(qq,0,getdate()),-1)
Start of Current Year
dateadd(yy, datediff(yy,0,getdate()), 0)
End of Current Year
dateadd(yy, datediff(yy,-1,getdate()), -1)
Start of Previous Year
dateadd(yyyy,-1,dateadd(yy, datediff(yy,0,getdate()), 0))
End of Previous Year
dateadd(yy, datediff(yy,1,getdate()), -1)
Again, note that this is simply manipulation of the sysdate functionality within SQL Server and should in no way detract from the importance of a calendar table. It should assist it.
Hope it helps,
Mark