The main use of SQL functions
DATEDIFF (datepart,startdate,enddate)
SQL statement with database table TableA (date field ddate)
--Query today
SELECT * from TableA where DateDiff (dd,voucherdate,getdate ()) = 0
--Query yesterday
SELECT * from TableA where DateDiff (dd,voucherdate,getdate ()) = 1
--Query this week
SELECT * from TableA where DateDiff (Dd,voucherdate,getdate ()) <=7
--Query last week
SELECT * from TableA where DateDiff (Dd,voucherdate,getdate ()) >7 and DateDiff (Dd,voucherdate,getdate ()) <=14
--Query this month
SELECT * from TableA where DateDiff (mm,voucherdate,getdate ()) = 0
--Query last month
SELECT * from TableA where DateDiff (mm,voucherdate,getdate ()) = 1
--Check this year
SELECT * from TableA where DateDiff (yy,voucherdate,getdate ()) = 0
--Query last year
SELECT * from TableA where DateDiff (yy,voucherdate,getdate ()) = 1
SQL Query--Date conditions (today, yesterday, this week, this month ...) )