Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
785 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

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 1000 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 1000 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

705 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