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

datetime question 1

Status
Not open for further replies.

foxphpbomb

Programmer
Apr 10, 2007
29
US
I have to sort a result by a datetime field so that it will show records for the past 24 hours and also for the past 7 days. I need 2 modified sql queries of the one below.

select * from table ORDER by datettimefield DESC
 
Code:
select * from table 
WHERE datetimefield >= date_sub(current_datetime, interval 24 hour)
ORDER by datettimefield DESC
Code:
select * from table 
WHERE datetimefield >= date_sub(current_date, interval 7 day)
ORDER by datettimefield DESC
notice the subtle difference in the second one :)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top