Solved

Access query - number of days between 2 datese

Posted on 2016-09-07
5
35 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 19
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 19
ID: 41788780
hi Patrick! ... hence my comment too ;)
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

825 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