FAO bizTech Team : Add frequently used SQL Snippets here.
Get Yesterday’s Date without, any time
-- Add -1 to current time + format without hours
Select DATEADD (day , -1 , CONVERT(varchar(10), getdate(), 101) )
T-SQL Get dates on a specific day when you don't care about time
Quite often I have to write queries to return rows where something happened on a specific day. But the values in the table could be anytime within that day.
Previous I would pass in a start date, end date to do this, but the query then needs 2 parameters and it looks a bit cumbersome.
I came across this method which I now employ. Don't know if this has much performance impact, but it certainly is quicker to code and takes less parameters from calling application.
Where
(
DateDiff(day, @ReportStartDate,TerminalSession.StartDate) = 0
--StartDate >= @ReportStartDate
--And
--EndDate >= @ReportEndDate
)