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 » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Months are different from days



 
 
Thread Tools Display Modes
  #1  
Old July 8th, 2008, 02:57 AM posted to microsoft.public.access.queries
Kevbro7189
external usenet poster
 
Posts: 35
Default Months are different from days

I have a query that looks at a table with a list of dates, and data. I want
to use the query to pull out everything with in the past 3 months (not days
like I have now (Now()-90). I’m trying to understand expressions in Access
so an explanation would be appreciated.
  #2  
Old July 8th, 2008, 04:14 AM posted to microsoft.public.access.queries
fredg
external usenet poster
 
Posts: 4,386
Default Months are different from days

On Mon, 7 Jul 2008 18:57:00 -0700, Kevbro7189 wrote:

I have a query that looks at a table with a list of dates, and data. I want
to use the query to pull out everything with in the past 3 months (not days
like I have now (Now()-90). I¢m trying to understand expressions in Access
so an explanation would be appreciated.


The Now() function includes the time of day and will therefore return
different record depending upon the time of day the query is run.
Use Date().

Within the last 3 months:

Between DateAdd("m",-3,Date()) and Date()

The above will work fine.... unless your data includes the time of day
as well as the date.
In that case you must add 1 day to the end date of the criteria:

Between DateAdd("m",-3,Date()) and DateAdd("d",1,Date())

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
  #3  
Old July 8th, 2008, 05:14 PM posted to microsoft.public.access.queries
Klatuu
external usenet poster
 
Posts: 7,074
Default Months are different from days

If the field to be compared does contain time, a more accurate test would be:
DateValue([SomeDateField]) Between DateAdd("m",-3,Date()) and Date()
--
Dave Hargis, Microsoft Access MVP


"fredg" wrote:

On Mon, 7 Jul 2008 18:57:00 -0700, Kevbro7189 wrote:

I have a query that looks at a table with a list of dates, and data. I want
to use the query to pull out everything with in the past 3 months (not days
like I have now (Now()-90). Iʼm trying to understand expressions in Access
so an explanation would be appreciated.


The Now() function includes the time of day and will therefore return
different record depending upon the time of day the query is run.
Use Date().

Within the last 3 months:

Between DateAdd("m",-3,Date()) and Date()

The above will work fine.... unless your data includes the time of day
as well as the date.
In that case you must add 1 day to the end date of the criteria:

Between DateAdd("m",-3,Date()) and DateAdd("d",1,Date())

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

  #4  
Old July 9th, 2008, 03:27 AM posted to microsoft.public.access.queries
Kevbro7189
external usenet poster
 
Posts: 35
Default Months are different from days

Thank you for your help. It worked

"fredg" wrote:

On Mon, 7 Jul 2008 18:57:00 -0700, Kevbro7189 wrote:

I have a query that looks at a table with a list of dates, and data. I want
to use the query to pull out everything with in the past 3 months (not days
like I have now (Now()-90). Iʼm trying to understand expressions in Access
so an explanation would be appreciated.


The Now() function includes the time of day and will therefore return
different record depending upon the time of day the query is run.
Use Date().

Within the last 3 months:

Between DateAdd("m",-3,Date()) and Date()

The above will work fine.... unless your data includes the time of day
as well as the date.
In that case you must add 1 day to the end date of the criteria:

Between DateAdd("m",-3,Date()) and DateAdd("d",1,Date())

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

 




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 08:39 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.