SQLTeam.com | Weblogs | Forums

8am to 6pm SQL Report


#1

Hi,

I am not an SQL programmer but run reports that were made by someone else. I have been asked to modify a report to only show data from between 8am to 6pm. The report is for the previous months data and currently has this

where DateTime > DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) AND DateTime < DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, 0)

What do i need to add/change to only get 8am to 6pm data ?

Thanks


#2

The easiest way would be to add this to the WHERE clause:

where DateTime > DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) AND DateTime < DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, 0)
and DATEPART(HOUR, DateTime) BETWEEN 8 AND 17