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
776 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
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33745196
SELECT TheDate, IIf(TheDate <= Date() + 15, "Yes", "No") AS Within15DaysFROM SomeTable
0
 
LVL 57
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
 

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 92

Expert Comment

by:Patrick Matthews
ID: 33747095
Please post your SQL statement.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 39

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now