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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SP selecting a date range to be fine-tuned to the hour 1

Status
Not open for further replies.

POSAPAY

IS-IT--Management
Jul 27, 2001
192
0
0
HU
My SP runs once an hour by a SQL job is selecting from the database a number of records that have a field with a date that is not older than 5 days, yet older by a variable passed in.
The problem is, my logic only names it by DAY, and not fine-tuned to the HOUR at least.

Code:
WHERE Active = 'T' AND (DateModified BETWEEN (GETDATE()-5) AND (GETDATE()-@AlertDays))

How can I change this to have it filter to the hour or better to the second?
 
Here is a neat solution to rounding GETDATE(): Extrapolating from that, I got these:
Code:
SELECT CONVERT(datetime, ROUND(CAST(GETDATE() AS float) * 24,0) / 24) AS RoundToHour
SELECT CONVERT(datetime, ROUND(CAST(GETDATE() AS float) * (24*60*60),0) / (24*60*60)) AS RoundToSecond
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top