How do I have access show me a query with just the last 5 days

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a shift log that all of my staff is using, and I need to show what has
been entered in the last 5 days up to the current day.

I currently have Query that shows this, but when the day or the month is a
single digit the then it shows data from much farther back.

For instance it is the 1st of Feb, so the last five days are Jan 27, 28, 29,
30 & 31.
My query shows all of December (12) all of October (10) all of November (11)
as well. the criteria I have in my query is
">=Date()-"1" And <=Date()"
Any help would be apreceated.
 
Oops - I guess you may have records with a date later than today? If so
then use:

Between Date()-5 and Date()
 
That still gives me all of the Dec, Nov, & Oct.

The field that I am using to sort on is one that is populated by Date()
And therefore does not have a leading 0 on the month or the day so it
formats m/d/yyyy
So the problem that I am having is that the query brings up all dates that
have a 1 in the month [example Jan(1), Oct(10), Nov(11), Dec(12)]
So I am still having the same problem.
Oh and I copied the wrong criteria
Then one that I have is ">=Date()-"5" And <=Date()"

Again any way around this problem would be appreciated.
Thank you to Rick B for trying
 
DROP the quotes around the 5. Your criteria should be
=Date()-5 And <=Date()
Which is the same as
Between Date()-5 and Date()

Which is what Rick B posted.

If that is not working then it is probable that your date field is not a
date field but is a text field containing a string that looks like a date.

Try posting the SQL text view of your query for further help.


Dax said:
That still gives me all of the Dec, Nov, & Oct.

The field that I am using to sort on is one that is populated by Date()
And therefore does not have a leading 0 on the month or the day so it
formats m/d/yyyy
So the problem that I am having is that the query brings up all dates that
have a 1 in the month [example Jan(1), Oct(10), Nov(11), Dec(12)]
So I am still having the same problem.
Oh and I copied the wrong criteria
Then one that I have is ">=Date()-"5" And <=Date()"

Again any way around this problem would be appreciated.
Thank you to Rick B for trying


Rick B said:
Oops - I guess you may have records with a date later than today? If so
then use:

Between Date()-5 and Date()
 
Still having the same problem

Here is the SQL View
SELECT change_log.Date, change_log.Time, change_log.Location,
change_log.Description, change_log.followup, change_log.field,
change_log.central, change_log.Temp, change_log.Arcived, change_log.Freeway,
change_log.Freeway_time, change_log.Completed, change_log.[Tech/person]
FROM change_log
WHERE (((change_log.Date)>=Now()-"5" And (change_log.Date)<=Now()))
ORDER BY change_log.Date DESC;

John Spencer said:
DROP the quotes around the 5. Your criteria should be
=Date()-5 And <=Date()
Which is the same as
Between Date()-5 and Date()

Which is what Rick B posted.

If that is not working then it is probable that your date field is not a
date field but is a text field containing a string that looks like a date.

Try posting the SQL text view of your query for further help.


Dax said:
That still gives me all of the Dec, Nov, & Oct.

The field that I am using to sort on is one that is populated by Date()
And therefore does not have a leading 0 on the month or the day so it
formats m/d/yyyy
So the problem that I am having is that the query brings up all dates that
have a 1 in the month [example Jan(1), Oct(10), Nov(11), Dec(12)]
So I am still having the same problem.
Oh and I copied the wrong criteria
Then one that I have is ">=Date()-"5" And <=Date()"

Again any way around this problem would be appreciated.
Thank you to Rick B for trying


Rick B said:
Oops - I guess you may have records with a date later than today? If so
then use:

Between Date()-5 and Date()

--
Rick B



I have a shift log that all of my staff is using, and I need to show
what
has
been entered in the last 5 days up to the current day.

I currently have Query that shows this, but when the day or the month
is a
single digit the then it shows data from much farther back.

For instance it is the 1st of Feb, so the last five days are Jan 27,
28,
29,
30 & 31.
My query shows all of December (12) all of October (10) all of November
(11)
as well. the criteria I have in my query is
">=Date()-"1" And <=Date()"
Any help would be apreceated.
 
still brings up
2/1/2006
2/1/2006
2/1/2006
2/1/2006
12/7/2005
12/7/2005
12/7/2005
12/7/2005
12/6/2005
12/6/2005
12/6/2005
12/6/2005
12/6/2005
12/6/2005
12/5/2005
12/5/2005
12/4/2005
12/31/2005
12/31/2005
12/31/2005
12/31/2005
12/31/2005
12/31/2005
12/31/2005
12/31/2005
12/3/2005
12/3/2005
12/3/2005
12/29/2005
12/29/2005
12/28/2005
12/28/2005
12/28/2005
12/28/2005
12/27/2005
12/27/2005
12/27/2005
12/23/2005
12/22/2005
12/21/2005
12/21/2005
12/21/2005
12/20/2005
12/20/2005
12/20/2005
12/20/2005
12/20/2005
12/2/2005
12/2/2005
12/19/2005
12/19/2005
12/17/2005
12/17/2005
12/17/2005
12/16/2005
12/16/2005
12/16/2005
12/16/2005
12/15/2005
12/15/2005
12/15/2005
12/14/2005
12/14/2005
12/14/2005
12/13/2005
12/13/2005
12/13/2005
12/12/2005
12/12/2005
12/10/2005
12/10/2005
12/1/2005
12/1/2005
12/1/2005
12/1/2005
12/09/2005
11/9/2005
11/9/2005
11/9/2005
11/9/2005
11/9/2005
11/7/2005
11/7/2005
11/7/2005
11/7/2005
11/7/2005
11/5/2005
11/4/2005
11/4/2005
11/30/2005
11/30/2005
11/30/2005
11/3/2005
11/3/2005
11/3/2005
11/3/2005
11/3/2005
11/3/2005
11/3/2005
11/28/2005
11/26/2005
11/26/2005
11/26/2005
11/26/2005
11/23/2005
11/23/2005
11/23/2005
11/23/2005
11/22/2005
11/22/2005
11/21/2005
11/2/2005
11/2/2005
11/2/2005
11/2/2005
11/19/2005
11/18/2005
11/17/2005
11/16/2005
11/16/2005
11/16/2005
11/16/2005
11/16/2005
11/15/2005
11/15/2005
11/15/2005
11/15/2005
11/15/2005
11/15/2005
11/14/2005
11/14/2005
11/14/2005
11/14/2005
11/14/2005
11/12/2005
11/12/2005
11/10/2005
11/10/2005
11/1/2005
11/1/2005
11/1/2005
11/1/2005
11/09/2005
11/09/2005
10/31/2005
10/31/2005
10/27/2005
10/27/2005
10/27/2005
10/27/2005
10/27/2005
10/27/2005
10/27/2005
10/27/2005
10/26/2005
10/26/2005
10/26/2005
10/25/2005
10/25/2005
10/25/2005
10/25/2005
10/24/2005
10/24/2005
10/24/2005
10/22/2005
10/22/2005
10/21/2005
10/21/2005
10/21/2005
10/21/2005
10/21/2005
10/21/2005
10/21/2005
10/21/2005
10/20/2005
10/20/2005
10/19/2005
10/19/2005
10/19/2005
10/19/2005
10/19/2005
10/19/2005
10/19/2005
10/19/2005
10/19/2005
10/19/2005
10/18/2005
10/17/2005
10/17/2005
10/14/2005
10/14/2005
10/14/2005
10/14/2005
10/13/2005
10/13/2005
10/13/2005
10/12/2005
10/12/2005
10/12/2005
10/12/2005
10/11/2005
10/10/2005
10/10/2005
10/10/2005
10/10/2005
10/10/2005
10/10/2005
10/10/2005
10/10/2005
10/08/2005
10/08/2005
10/07/2005
10/07/2005
10/07/2005
10/07/2005
10/07/2005
10/07/2005
10/06/2005
10/06/2005
10/05/2005
10/05/2005
10/05/2005
10/05/2005
10/04/2005
10/04/2005
10/04/2005
10/03/2005
10/03/2005
1/9/2006
1/9/2006
1/9/2006
1/6/2006
1/5/2006
1/5/2006
1/5/2006
1/4/2006
1/4/2006
1/4/2006
1/3/2006
1/3/2006
1/3/2006
1/28/2006
1/28/2006
 
I set up a table with one field, Date, formatted with the Date option.
I copied and pasted your data into the field. I ran the following
query:

SELECT datetable.Date
FROM [datetable]
WHERE (((datetable.Date)>=Now()-5 And (datetable.Date)<=Now()))

It worked fine.

if you feel comfortable with me looking at your work, export the table
and the query into a database and attach it to an email to
(e-mail address removed). I'll examine the table and query structure.
 
NOTE the change in the WHERE clause.
SELECT change_log.Date, change_log.Time, change_log.Location,
change_log.Description, change_log.followup, change_log.field,
change_log.central, change_log.Temp, change_log.Arcived, change_log.Freeway,
change_log.Freeway_time, change_log.Completed, change_log.[Tech/person]
FROM change_log
WHERE (((change_log.Date)>=Date()-5 And (change_log.Date)<=Date()))
ORDER BY change_log.Date DESC;

IF this doesn't work, then please open your Change_log table in design view
and make sure the changelog.Date field is a DateTime field. If it isn't
then you can try modifying the query or fixing the data type. Modify the
query by forcing the date field to become a datetime field using the
following where clause.

SELECT change_log.Date, change_log.Time, change_log.Location,
change_log.Description, change_log.followup, change_log.field,
change_log.central, change_log.Temp, change_log.Arcived, change_log.Freeway,
change_log.Freeway_time, change_log.Completed, change_log.[Tech/person]
FROM change_log
WHERE (((DateValue(change_log.Date))>=Date()-5 And
DateValue((change_log.Date))<=Date()))
ORDER BY change_log.Date DESC;

Dax said:
Still having the same problem

Here is the SQL View
SELECT change_log.Date, change_log.Time, change_log.Location,
change_log.Description, change_log.followup, change_log.field,
change_log.central, change_log.Temp, change_log.Arcived,
change_log.Freeway,
change_log.Freeway_time, change_log.Completed, change_log.[Tech/person]
FROM change_log
WHERE (((change_log.Date)>=Now()-"5" And (change_log.Date)<=Now()))
ORDER BY change_log.Date DESC;

John Spencer said:
DROP the quotes around the 5. Your criteria should be
=Date()-5 And <=Date()
Which is the same as
Between Date()-5 and Date()

Which is what Rick B posted.

If that is not working then it is probable that your date field is not a
date field but is a text field containing a string that looks like a
date.

Try posting the SQL text view of your query for further help.


Dax said:
That still gives me all of the Dec, Nov, & Oct.

The field that I am using to sort on is one that is populated by Date()
And therefore does not have a leading 0 on the month or the day so it
formats m/d/yyyy
So the problem that I am having is that the query brings up all dates
that
have a 1 in the month [example Jan(1), Oct(10), Nov(11), Dec(12)]
So I am still having the same problem.
Oh and I copied the wrong criteria
Then one that I have is ">=Date()-"5" And <=Date()"

Again any way around this problem would be appreciated.
Thank you to Rick B for trying


:

Oops - I guess you may have records with a date later than today? If
so
then use:

Between Date()-5 and Date()

--
Rick B



I have a shift log that all of my staff is using, and I need to show
what
has
been entered in the last 5 days up to the current day.

I currently have Query that shows this, but when the day or the
month
is a
single digit the then it shows data from much farther back.

For instance it is the 1st of Feb, so the last five days are Jan 27,
28,
29,
30 & 31.
My query shows all of December (12) all of October (10) all of
November
(11)
as well. the criteria I have in my query is
">=Date()-"1" And <=Date()"
Any help would be apreceated.
 
Thanks That did the trick

John Spencer said:
NOTE the change in the WHERE clause.
SELECT change_log.Date, change_log.Time, change_log.Location,
change_log.Description, change_log.followup, change_log.field,
change_log.central, change_log.Temp, change_log.Arcived, change_log.Freeway,
change_log.Freeway_time, change_log.Completed, change_log.[Tech/person]
FROM change_log
WHERE (((change_log.Date)>=Date()-5 And (change_log.Date)<=Date()))
ORDER BY change_log.Date DESC;

IF this doesn't work, then please open your Change_log table in design view
and make sure the changelog.Date field is a DateTime field. If it isn't
then you can try modifying the query or fixing the data type. Modify the
query by forcing the date field to become a datetime field using the
following where clause.

SELECT change_log.Date, change_log.Time, change_log.Location,
change_log.Description, change_log.followup, change_log.field,
change_log.central, change_log.Temp, change_log.Arcived, change_log.Freeway,
change_log.Freeway_time, change_log.Completed, change_log.[Tech/person]
FROM change_log
WHERE (((DateValue(change_log.Date))>=Date()-5 And
DateValue((change_log.Date))<=Date()))
ORDER BY change_log.Date DESC;

Dax said:
Still having the same problem

Here is the SQL View
SELECT change_log.Date, change_log.Time, change_log.Location,
change_log.Description, change_log.followup, change_log.field,
change_log.central, change_log.Temp, change_log.Arcived,
change_log.Freeway,
change_log.Freeway_time, change_log.Completed, change_log.[Tech/person]
FROM change_log
WHERE (((change_log.Date)>=Now()-"5" And (change_log.Date)<=Now()))
ORDER BY change_log.Date DESC;

John Spencer said:
DROP the quotes around the 5. Your criteria should be
=Date()-5 And <=Date()
Which is the same as
Between Date()-5 and Date()

Which is what Rick B posted.

If that is not working then it is probable that your date field is not a
date field but is a text field containing a string that looks like a
date.

Try posting the SQL text view of your query for further help.


That still gives me all of the Dec, Nov, & Oct.

The field that I am using to sort on is one that is populated by Date()
And therefore does not have a leading 0 on the month or the day so it
formats m/d/yyyy
So the problem that I am having is that the query brings up all dates
that
have a 1 in the month [example Jan(1), Oct(10), Nov(11), Dec(12)]
So I am still having the same problem.
Oh and I copied the wrong criteria
Then one that I have is ">=Date()-"5" And <=Date()"

Again any way around this problem would be appreciated.
Thank you to Rick B for trying


:

Oops - I guess you may have records with a date later than today? If
so
then use:

Between Date()-5 and Date()

--
Rick B



I have a shift log that all of my staff is using, and I need to show
what
has
been entered in the last 5 days up to the current day.

I currently have Query that shows this, but when the day or the
month
is a
single digit the then it shows data from much farther back.

For instance it is the 1st of Feb, so the last five days are Jan 27,
28,
29,
30 & 31.
My query shows all of December (12) all of October (10) all of
November
(11)
as well. the criteria I have in my query is
">=Date()-"1" And <=Date()"
Any help would be apreceated.
 
Just to satisfy my curiousity.

Can you expand on which solution you are referring to when you say "That,
did the trick"

The first query that I proposed? The query using DateValue? Or changing
the field type?

Dax said:
Thanks That did the trick

John Spencer said:
NOTE the change in the WHERE clause.
SELECT change_log.Date, change_log.Time, change_log.Location,
change_log.Description, change_log.followup, change_log.field,
change_log.central, change_log.Temp, change_log.Arcived,
change_log.Freeway,
change_log.Freeway_time, change_log.Completed, change_log.[Tech/person]
FROM change_log
WHERE (((change_log.Date)>=Date()-5 And (change_log.Date)<=Date()))
ORDER BY change_log.Date DESC;

IF this doesn't work, then please open your Change_log table in design
view
and make sure the changelog.Date field is a DateTime field. If it isn't
then you can try modifying the query or fixing the data type. Modify the
query by forcing the date field to become a datetime field using the
following where clause.

SELECT change_log.Date, change_log.Time, change_log.Location,
change_log.Description, change_log.followup, change_log.field,
change_log.central, change_log.Temp, change_log.Arcived,
change_log.Freeway,
change_log.Freeway_time, change_log.Completed, change_log.[Tech/person]
FROM change_log
WHERE (((DateValue(change_log.Date))>=Date()-5 And
DateValue((change_log.Date))<=Date()))
ORDER BY change_log.Date DESC;

Dax said:
Still having the same problem

Here is the SQL View
SELECT change_log.Date, change_log.Time, change_log.Location,
change_log.Description, change_log.followup, change_log.field,
change_log.central, change_log.Temp, change_log.Arcived,
change_log.Freeway,
change_log.Freeway_time, change_log.Completed, change_log.[Tech/person]
FROM change_log
WHERE (((change_log.Date)>=Now()-"5" And (change_log.Date)<=Now()))
ORDER BY change_log.Date DESC;

:

DROP the quotes around the 5. Your criteria should be
=Date()-5 And <=Date()
Which is the same as
Between Date()-5 and Date()

Which is what Rick B posted.

If that is not working then it is probable that your date field is not
a
date field but is a text field containing a string that looks like a
date.

Try posting the SQL text view of your query for further help.


That still gives me all of the Dec, Nov, & Oct.

The field that I am using to sort on is one that is populated by
Date()
And therefore does not have a leading 0 on the month or the day so
it
formats m/d/yyyy
So the problem that I am having is that the query brings up all
dates
that
have a 1 in the month [example Jan(1), Oct(10), Nov(11), Dec(12)]
So I am still having the same problem.
Oh and I copied the wrong criteria
Then one that I have is ">=Date()-"5" And <=Date()"

Again any way around this problem would be appreciated.
Thank you to Rick B for trying


:

Oops - I guess you may have records with a date later than today?
If
so
then use:

Between Date()-5 and Date()

--
Rick B



I have a shift log that all of my staff is using, and I need to
show
what
has
been entered in the last 5 days up to the current day.

I currently have Query that shows this, but when the day or the
month
is a
single digit the then it shows data from much farther back.

For instance it is the 1st of Feb, so the last five days are Jan
27,
28,
29,
30 & 31.
My query shows all of December (12) all of October (10) all of
November
(11)
as well. the criteria I have in my query is
">=Date()-"1" And <=Date()"
Any help would be apreceated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top