Solved

Access query - number of days between 2 datese

Posted on 2016-09-07
5
24 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
  • 2
5 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) 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 18
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 92

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 18
ID: 41788780
hi Patrick! ... hence my comment too ;)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

707 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

13 Experts available now in Live!

Get 1:1 Help Now