Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get records from last 7 days in access

Posted on 2010-08-26
4
Medium Priority
?
855 Views
Last Modified: 2012-05-10
I need to filter my "Created Date" column in access by the last 7 days.  The date format is as follows MM/DD/YYYY HR:MIN:SEC AM/PM

any help is appreciated
0
Comment
Question by:KnutsonBM
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33531292


select * from tablex
where datevalue([createdDate])<=Date()-7

or

select * from tablex
where datevalue([createdDate])<=DateAdd("d",-7,Date())

0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 33531308
it is the other way around



select * from tablex
where datevalue([createdDate])>=Date()-7

or

select * from tablex
where datevalue([createdDate])>=DateAdd("d",-7,Date())

0
 
LVL 11

Expert Comment

by:LambertHeenan
ID: 33531536
Just a comment to highlight that  the *format* of the date is not particularly relevant as that is only how the date is *displayed*. However as your date field does include the time of day that will effect the SQL that you need to select data from the last seven days.

The reason is that Date() returns just a bare date, with no apparent time value, but that is misleading because 8/26/2010 really means MIDNIGHT on 8/26/2010, ie. just after we moved from 8/25/2010.

That is why capricorn1 uses datevalue([createdDate]) in the SQL as datevalue gets rid of the time portion, and so you can be sure that records with any time value will get included as long as the date part is 7 days ago.
0
 
LVL 6

Author Closing Comment

by:KnutsonBM
ID: 33531618
Works great, had some issues for a minute until i realized i told you the wrong name, it wasnt createdDate, it was CreateDate
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question