Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
results page - order by date and limit amount of days
Old 01-27-2005, 04:57 AM results page - order by date and limit amount of days
webgurl's Avatar
Skilled Talker

Posts: 70
Location: Australia
Trades: 0
I have a page that shows new listings of properties for sale and I order by the date they were listed. Works great except I do not want to see every listing, just the ones for the last 7 days.

SELECT *
FROM for_sale
ORDER BY ListDate Desc

Could someone please help me restrict what can be seen


Thanks
webgurl is offline
Reply With Quote
View Public Profile Visit webgurl's homepage!
 
 
Register now for full access!
Old 01-27-2005, 09:03 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Use the DATEDIFF mysql function. Give this a try:

SELECT * FROM for_sale WHERE DATEDIFF(today(), ListDate) <= 7 ORDER BY ListDate Desc

DATEDIFF always substracts the second term from the first, so be sure you always put the later date (in this case, today()), as the first term otherwise the logic will be off as the result would be a negative number.

On a tangent: That, too, could be solved using some function to determine the absolute value -- but again, the above call should work for you (although I have no means to test it where I am).
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 01-27-2005, 02:15 PM
Junior Talker

Posts: 2
Location: England
Trades: 0
Try:

SELECT *
FROM for_sale
WHERE ListDate>=DateAdd("d",-7,Now())
ORDER BY LisrDate DESC;

This seems to work in Access.

Hope it helps!.
kingrich is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to results page - order by date and limit amount of days
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44711 seconds with 12 queries