Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find last hour 1

Status
Not open for further replies.

IanWaterman

Programmer
Joined
Jun 26, 2002
Messages
3,511
Location
GB
I need to run a report hourly and data must be returned from entries in last hour. Report will be scheduled but will not execute exactly on the hour.

If report runs at

26/04/2010 11:05:00 I must filter data where

datetimefield >= 26/04/2010 10:00:00 and
datetimefield < 26/04/2010 11:00:00

Once I have one of the times I can derive the other by using dateadd to add or subtract 1 hour.

Thank you

Ian
 
Try this
Code:
DECLARE @EndDate DATETIME
DECLARE @StartDate DATETIME
SELECT @EndDate = CONVERT(DATETIME, CONVERT(VARCHAR(13), GETDATE(), 127) + ':00:00.000')
SELECT @StartDate = DATEADD(hour, -1, @EndDate)

PRINT @StartDate 
PRINT @EndDate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top