Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I'm in design view for MS Access and I'm creating a query where it selects a list of patients admitted within the last 24 hours. I'm not sure how to do this for my DATE_ADMITTED column, Criteria field. Any help?

share|improve this question
up vote 3 down vote accepted

If the DATE_ADMITTED field is a real date/time field, then you can set the criteria of the DATE_ADMITTED field to:


That would filter the query results to the past 24 hours down to the second in which the query was run.

For the query to return yesterday and today use:


This should cover from yesterday 12:00:00 AM (midnight) to today 11:59:59 PM (midnight).

Of course the above criteria doesn't check for future dates/times. If on the off chance you need to ensure no future dates/times are included in the query results the two queries below will filter those out.

>=Now()-1 And <Now()

>=Date()-1 And <Date()+1

Website for criteria examples:

Video Series (on Google Video):

When you say last Friday, I take that the previous Friday (not the last Friday of the month or something).

Here is a query that will return the results for the previous Friday, and if executed on a Friday will still return the results of the previous Friday and not the current Friday.
(Weekday([DATE_ADMITTED])=6) And (DateDiff("d",[DATE_ADMITTED],Now())<=7) And (DateDiff("d",[DATE_ADMITTED],Now())>0)

If by 'from last Friday' you meant from the previous Friday until now then here are some criteria depending on the days you want included:

From current or previous Friday until now (if run on a Friday then will return only the current Friday results only)
Between Date() And Date()-(IIf((Weekday(Date())>=6),(Weekday(Date())-6),(Weekday(Date())+1)))

From previous Friday until now (if run on a Friday it will including current Friday in the results) (Includes current Friday if today is Friday.)
Between Date() And Date()-(IIf((Weekday(Date())>6),(Weekday(Date())-6),(Weekday(Date())+1)))

From previous Friday until now (unless run on a Friday, then will be from previous Friday until Thur). (Excludes current Friday, if today is Friday.)
Between Date()-(IIf((Weekday(Date())=6),1,0)) And Date()-(IIf((Weekday(Date())>6),(Weekday(Date())-6),(Weekday(Date())+1)))

NOT usage - Here is a website that show some examples of NOT.

Hope this helps.

share|improve this answer
It all depends on the definition of "last 24 hours" -- if it's a strict definition, your solution will work, but people often define precise terms like "last 24 hours" to mean something more general, like "within the last day" which loosely means more like >=Date()-1 (i.e., anything after midnight yesterday). – David W. Fenton Oct 1 '10 at 22:56
+1, good point. Sometimes computer people can be too literal. :) – Scott McClenning Oct 2 '10 at 3:18
My project description wasn't too specific on the 24 hours. Thanks Scott! – FlavorOfLife Oct 3 '10 at 6:14
The two ways I learned Access queries was by pressing F1 (which in 2010 is of no real help, unlike in 2000 or 2003), and using the Expression Builder. (in 2010 it is under Query Tools Design tab, Query Setup section, Builder). In the Expression Builder under Functions, Built-in Functions will be the keywords and usages. Clicking on the usage will pull up a help screen with examples at the bottom. I will have to research some sites, usually I would Google the keyword for additional help, but I'm sure there must be tutorial sites out there. If I find some I will post it. – Scott McClenning Oct 3 '10 at 6:43
Correct NOT would exclude Friday vice include Friday. Sometimes when working with compound statements you would need to change the ANDs to AND NOT. – Scott McClenning Oct 5 '10 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .