Solved

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

Posted on 2010-09-23
13
783 Views
Last Modified: 2013-11-27
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
Comment
Question by:daintysally
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 33745196
SELECT TheDate, IIf(TheDate <= Date() + 15, "Yes", "No") AS Within15DaysFROM SomeTable
0
 
LVL 58
ID: 33745205
Define a column as:

DaysAway: DateDiff("d",Now(), <DateFieldName>)
and then put a criteria check on it of <16
JimD.
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33745232
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
Industry Leaders: 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!

 

Author Comment

by:daintysally
ID: 33746384
I am doing this in a query.
0
 

Author Comment

by:daintysally
ID: 33746581
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
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 33747095
Please post your SQL statement.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 33747128
Your example shows three dates, nothing else.
0
 

Author Comment

by:daintysally
ID: 33747184
SELECT IIF(DateDiff("d",Now(),[TABLENAME].[DATE])<16,"YES","NO") AS DATE_15_DAYS_OUT
INTO NEWTABLE
FROM TABLENAME;
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33747369
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
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33747377
sorry that last one should be:

IIf(DateDiff("d", Date, DateAdd("d", 40, Date)) < 16, "yes <16", "no >=16"))
0
 
LVL 44

Accepted Solution

by:
GRayL earned 250 total points
ID: 33747396
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
 
LVL 40

Assisted Solution

by:als315
als315 earned 250 total points
ID: 33759447
Are you sure in field type? This is example, where your text is working
Sample.zip
0
 

Author Closing Comment

by:daintysally
ID: 33772717
Thanks for all of your help.  It works fine now!!!
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question