A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

how to get records from a range of dates relative to current date



 
 
Thread Tools Display Modes
  #1  
Old April 22nd, 2009, 05:31 PM posted to microsoft.public.access
Cathy C.
external usenet poster
 
Posts: 1
Default how to get records from a range of dates relative to current date

I want to run a report daily that gives me the last week's records. I used
to use "Between DateRelToday(-7) and DateRelToday(0)", but that doesn't seem
to work anymore.
  #2  
Old April 22nd, 2009, 06:02 PM posted to microsoft.public.access
Clifford Bass[_2_]
external usenet poster
 
Posts: 1,295
Default how to get records from a range of dates relative to current date

Hi Cathy,

Use:

Between DateAdd("d", -6, Date()) And Date()

To get the last seven days, including the current date. Or:

Between DateAdd("d", -7, Date()) And DateAdd("d", -1, Date())

To get the last seven days, excluding the current date.

Clifford Bass

"Cathy C." wrote:

I want to run a report daily that gives me the last week's records. I used
to use "Between DateRelToday(-7) and DateRelToday(0)", but that doesn't seem
to work anymore.

  #3  
Old April 22nd, 2009, 06:04 PM posted to microsoft.public.access
Ken Sheridan
external usenet poster
 
Posts: 3,433
Default how to get records from a range of dates relative to current date

I assume that DateRelToday is ( or was) a function in your database, but you
don't really need to call that; you can use the built in DateAdd function.
As the criteria for the relevant date column in a query on which the report
is based put:

Between DateAdd("d",-6,Date) And Date

which will return the last seven days, including today. For the last seven
days prior to today you'd use:

Between DateAdd("d",-7,Date) And DateAdd("d",-1,Date)

One caveat he the use of a Between…And operation does assume that none
of the values in the column have dates with a non-zero time of day. Unless
you've taken specific steps to prevent this in the table design you cannot
absolutely guarantee that this will be the case. Any rows with dates on the
last day of the range with non-zero times of day would not be returned. This
is because a 'date value' is really the point in time at midnight at the
start of the day, so any with a time of day after that will not equate with
the 'date value'. You can cover this possibility by using the following
criterion:

= DateAdd("d",-6,Date) And [YourDateField] DateAdd("d",1,Date)


or for the last seven days prior to today:

= DateAdd("d",-7,Date) And [YourDateField] Date


where YourDateField is the name of the column in question. Note that if you
do use this more 'bulletproof' expression for the criteria, if you save the
query and then open it again in design view you'll find Access will have
moved things around a bit. It will still work the same however.

Ken Sheridan
Stafford, England

"Cathy C." wrote:

I want to run a report daily that gives me the last week's records. I used
to use "Between DateRelToday(-7) and DateRelToday(0)", but that doesn't seem
to work anymore.


  #4  
Old April 22nd, 2009, 06:18 PM posted to microsoft.public.access
John Spencer MVP
external usenet poster
 
Posts: 533
Default how to get records from a range of dates relative to currentdate

"that doesn't seem to work anymore"

Can you be a bit more explicit? Do you get an error message? Do you get the
wrong results? If you get an error message then it probably means that
DateRelToday is a custom VBA function that you have not copied to the current
database.

Also, define last week's records - the last seven days of records or the
records for the prior week (Sunday to Saturday).

Prior 7 days and today
Between DateAdd("d",-7,Date()) and Date()

Prior 7 days not including today
Between DateAdd("d",-7,Date()) and DateAdd("d",-1,Date())

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Cathy C. wrote:
I want to run a report daily that gives me the last week's records. I used
to use "Between DateRelToday(-7) and DateRelToday(0)", but that doesn't seem
to work anymore.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:36 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.