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

Get data for last 5 hours

Status
Not open for further replies.

nelco

Programmer
Apr 4, 2006
93
US
Hi,
I have a date time field in a table, and based on this field, I want to get the data for the last 5 hours. Any idea on how to accomplish this?

Any help would be appreciated.
Thanks!
 
SELECT * FROM YourTable
WHERE YourDateTimeColumn >= DATEADD(hour, -5, GETDATE())
 
Thanks Riverguy. It worked.
I have one more question:
The columns that I am interested in a table are:
Deal_No. Deal_Date
If I have to count the Deal_No. for every min(In Deal_Date), how can this be done?
 
By "min," do you mean minute, or MIN as in the SQL Server MINIMUM function?
 
nelco,

Do you want to show 0's? I mean... if there are no rows for 8:40 AM, should that row be omitted from the results, or do you want to see the row with a count of 0?




-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
0's are fine(they should be part of results). Thanks George for your help.
 
Nevermind, I answered in your other thread. To use zero's, you're going to have to use a static table to join on or a derived/temporary table or variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top