Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 790
  • Last Modified:

How to calculate 15 days from today's date based off of a date field in access table

Hello Experts,

I am trying to identify rows where the date field in that row is 15 days out from today's date.  I want to create another column that tells me whether or not the date is 15 days or less away. Please see my date example below

DATE
06/01/2011
11/01/2010
10/01/2010
10/17/2010
0
daintysally
Asked:
daintysally
  • 4
  • 3
  • 2
  • +3
2 Solutions
 
Patrick MatthewsCommented:
SELECT TheDate, IIf(TheDate <= Date() + 15, "Yes", "No") AS Within15DaysFROM SomeTable
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Define a column as:

DaysAway: DateDiff("d",Now(), <DateFieldName>)
and then put a criteria check on it of <16
JimD.
0
 
jrm213jrm213Commented:
use a combination of dateadd and datediff to accomplish this, could you give more info on how you are doing this? Since you have this in zones for Query Syntax and Access Coding/Macros I wasn't sure how you were doing this. Is it a Query or a Module?

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
daintysallyAuthor Commented:
I am doing this in a query.
0
 
daintysallyAuthor Commented:
I tried

DATE 15 DAYS OUT: IIf(DateDiff("d",Now(),[TABLENAME].[DATE])<16,"YES","NO"):

When I try this without the <16 criteria, it calculates the days accurately.  However, when I added the criteria, it doesn't calculate accurately.  Thoughts?
0
 
Patrick MatthewsCommented:
Please post your SQL statement.
0
 
GRayLCommented:
Your example shows three dates, nothing else.
0
 
daintysallyAuthor Commented:
SELECT IIF(DateDiff("d",Now(),[TABLENAME].[DATE])<16,"YES","NO") AS DATE_15_DAYS_OUT
INTO NEWTABLE
FROM TABLENAME;
0
 
jrm213jrm213Commented:
I am not sure why it is not working for you, I just wanted to be sure that your fields are date fields, you are using Now() function which returns a datetime, Date() function just returns a date...

If your field data includes time values then datediff when comparing against another time (especially one that changes, as Now() does) you might get unexpected results especially if you are displaying your dates in a field formatted/masked to only show date format.

I have run:

IIf(DateDiff("d", Date, DateAdd("d", 16, Date)) < 16, "yes <16", "no >=16"))
result: no >=16
IIf(DateDiff("d", Date, DateAdd("d", 15, Date)) < 16, "yes <16", "no >=16"))
result: yes <= 15
IIf(DateDiff("d", Date, DateAdd("d", 1, Date)) < 16, "yes <16", "no >=16"))
result: yes <= 15
IIf(DateDiff("d", Date, DateAdd("d", 1, Date)) < 16, "yes <16", "no >=16"))
result: no >= 16
0
 
jrm213jrm213Commented:
sorry that last one should be:

IIf(DateDiff("d", Date, DateAdd("d", 40, Date)) < 16, "yes <16", "no >=16"))
0
 
GRayLCommented:
I think you also want to see the date.  Try this:

SELECT TABLENAME.[DATE], IIF(DateDiff("d",Now(),[TABLENAME].[DATE])<16,"YES","NO") AS DATE_15_DAYS_OUT
INTO NEWTABLE FROM TABLENAME;
0
 
als315Commented:
Are you sure in field type? This is example, where your text is working
Sample.zip
0
 
daintysallyAuthor Commented:
Thanks for all of your help.  It works fine now!!!
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 4
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now