Solved

Access query - number of days between 2 datese

Posted on 2016-09-07
5
44 Views
Last Modified: 2016-10-03
Hi,

I would like to know, in a query, how can I calculate the numbers of days between 2 dates

Thanks
0
Comment
Question by:Karl001
[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
  • 2
5 Comments
 
LVL 48

Accepted Solution

by:
Dale Fye earned 500 total points
ID: 41788169
You can use the DateDiff() function:

DaysBetween:DateDiff("d", [StartDate], [EndDate])

Note that for consecutive days this will return the value 1.  Basically, this takes the integer portion of the [EndDate] and subtracts the integer portion of [StartDate].
0
 
LVL 21
ID: 41788238
adding on: if date also contains a time component, you can test this and subtract one day if time for comparison date is greater than time for the first date since a full day(s) will not have passed.
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 41788648
Depends on what you need to know.  For example, as Dale noted, you could use DateDiff, but what that delivers is the number of time period boundaries between two date/time values.

For example, consider these two values:

2016-09-05 23:59:59
2016-09-07 00:00:00

DateDiff using "d" for the interval length, would return two.  In terms of true time elapsed, it's one day plus one second.

So, what specifically are you trying to calculate?
0
 
LVL 21
ID: 41788780
hi Patrick! ... hence my comment too ;)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

635 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