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

using dates in query

Status
Not open for further replies.

kristinac

Programmer
Jul 18, 2003
98
US
I would like to write a SQL statement that will retrieve all records entered within a certain time period. There is a field in my table called DateCreated. I want my users to be able to request all records created within say, the past 6 months. Except I have no idea how to ask that question using SQL. Is it possible?
 
HAVING (((table.DATE)>=[Start Date] And (table.DATE)<=[Stop Date]))
 
Thanks I will try that. The only problem is that the start date and stop date will change depending on the date and the user's choice. I guess I will have to calculate the date through my code prior to sending the SQL statement. I can't seem to find a way to say &quot;within 30 days&quot; &quot;within 60 days&quot; etc. without putting an actual date in the statement.
 
WHERE DateCreated BETWEEN DateAdd(&quot;d&quot;,-30,Date()) AND Date()

... will give you the past 30 days.
 
Thank you very much, that helped a lot. I used something very similar to what you sent and it's working great. Sorry if these are dumb questions but I've never done SQL statements with this kind of criteria.

Thank you!!:->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top