Solved

How do I use a formula that countdowns to a certain date (in Microsoft Access 2003) and then run a query that finds all less than 30 dates?

Posted on 2009-07-13
6
245 Views
Last Modified: 2012-05-07
In my Access database (named Audit Issues) I have a field named Days to Target Date. I need to run some kind of math formula that will calculate and countdown how many days from the current date to the target date. For example, if the target date is January 1, 2010 something that will countdown until that date  so if I am entering data today (July 13, 2009) the calculation will have 172 days appear.

Further, I need to learn how to run a query so that I can sort my table and eventually run a report that finds all data entries in this field (Days to Target Date) that are less than 30 days until target date and less than 60 days until target date. First, how do I go about running a query and second how do I run/use one under these two conditions?

I am a beginner to Microsoft Access (using version 2003), so detailed and step by step procedures/directions would be greatly appreciated. Thank you very much for all of your help, Experts Exchange has been great so far.
0
Comment
Question by:MaeMcG
  • 3
  • 2
6 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 24844132
Firstly, you can use the DateDiff function provided with MS Access to determine the days difference from today (can use Date() function to get that) and date specified in the future.

SELECT DATEDIFF("d", DATE(), #2010-01-01#);

If you have been storing this data all along into your field of how many days until the target date, you can just do your query like this:

SELECT *
FROM your_table
WHERE days_til_target < 30;

--OR

SELECT *
FROM your_table
WHERE days_til_target < 60;

If you want to calculate this on data that already exists with say a date field, you can use the DateDiff function again like this.

SELECT *
FROM your_table
WHERE DATEDIFF("d", date_field, #2010-01-01#) < 30;

Hopefully that is clear and helps.

Best regards,
Kevin
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 24848883
You should not store the 'number of days to target' as a table column - its value obviously changes from day to day and would therefore require to be updated each day. Instead store the Target date in the table and calculate the days-to-target whenever it needs to be shown:

Select Field1, Field2, ..., datediff("d", Date(), TargetDate) as DaysToTarget From MyTable

For the 30, 60 day selection, add a Where clause:

Select Field1, Field2, ..., datediff("d", Date(), TargetDate) as DaysToTarget From MyTable
Where datediff("d", Date(), TargetDate) <=30
0
 

Author Comment

by:MaeMcG
ID: 24849336
Hi MikeToole - I need to have it as a column and then update it accordingly each time (as frustrating as that is) -- do you know how I would go about doing that? Thanks very much!
0
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.

 
LVL 27

Expert Comment

by:MikeToole
ID: 24849496
What do you need the column for? Any access to the data that requires the Days to Target value should be via a a Select statement  that calculates it - that's how it's done.
What database are you using?
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24850179
I already showed and explained this all yesterday -- http:#24844132.
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 24850622
Sorry, yes your initial post said Access - I was looking at the URL for the Question which just said SQL_Syntax.
But the question still remains: Why does 'Days to Target' need to be physically stored as a column in the table? I can't think of any reason to design it that way.
If it is an absolute requirement then you're going to need a scheduled daily batch job to maintain the column.
0

Featured Post

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
return result by latest date - oracle query 21 69
Create A query for disabled users 5 29
SyBase Query Syntax Date Time conversion 4 27
SQL Query Syntax Join 4 27
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

914 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