Mainly using database built-in functions
From: http://www.cnblogs.com/aijun/archive/2011/03/18/1987750.html
SQL queries today's records:
Datediff (day, [datetime], getdate () = 0 replace datetime with your corresponding field;
SQL query records of yesterday:
Datediff (day, [datetime], getdate () = 1 replace datetime with your corresponding field. getdate ()-datetime is the time difference.
This month's record:
Select * from table where datediff (month, [dateadd], getdate () = 0
Weekly record:
Select * from table where datediff (Week, [dateadd], getdate () = 0
Current day record:
Select * from table where datediff (day, [dateadd], getdate () = 0
function |
parameters/functions |
getdate () |
returns the current date and time of the system |
datediff (interval, date1, date2) |
returns the difference date2-date1 between date2 and date1 in the form specified by interval |
dateadd (interval, number, date) |
Add the date after number in the format specified by interval |
datepart (interval, date) |
return the integer corresponding to the part specified by interval in date |
datename (interval, date) |
in date, |