Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get records from last 7 days in access

Posted on 2010-08-26
4
Medium Priority
?
798 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

671 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