Solved

Calculate number of days in query

Posted on 2011-09-13
4
337 Views
Last Modified: 2012-05-12
Experts,
Here a query I'm developing that calculates a future date based upon a date in my table.
I would like to be able to subtract maturityDate from dateID to show the number of actual days.
One final thing. Will the query as presented take into account leap years? If not, how does one handle leap years.

SELECT tblDate.DateID, DateSerial(Year([dateID]),Month([dateID]),Day([DateID])+30) AS maturityDate
FROM tblDate;
0
Comment
Question by:Frank Freese
  • 2
4 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 36529336
<Will the query as presented take into account leap years? > Yes

<I would like to be able to subtract maturityDate from dateID to show the number of actual days>

the actual days difference is already in your query (30)

anyway

SELECT tblDate.DateID, DateSerial(Year([dateID]),Month([dateID]),Day([DateID])+30) AS maturityDate, DateDiff("d",[DateID],[maturityDate]) as NDays
FROM tblDate
0
 

Author Comment

by:Frank Freese
ID: 36529357
thanks cap: I know my actual days are in the query, but my boss wants to see the Access calculation to reassure himself the query is right.
0
 

Author Closing Comment

by:Frank Freese
ID: 36529359
thank you
0
 
LVL 15

Expert Comment

by:OMC2000
ID: 36529379
maturityDate was defined in the same statement and cannot be used here as operand of select expression. And why we need functions here I always use direct operations and it used to work

SELECT tblDate.DateID, DateID+30 AS maturityDate, SomeDateField - SomeOtherDateField as NDays
FROM tblDate
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

910 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

22 Experts available now in Live!

Get 1:1 Help Now