Date/Time gaps - Find next date using correlated subquery
From time to time, I deal with data that is supposed to be taken on a daily basis. But there are times when there are gaps in the data. And that is a problem because I need to know how many data gaps I have and how long each gaps lasts. In a spreadsheet, it's simple enough to look for the data gaps albeit much harder to create a list of the gaps and the length for a large amount of data. However, I was wondering how I'd do it in an Access database. Well, after a little bit of thought, this is what I came up with.
Let's say we have some data that looks like this:
Date |
---|
1/1/2018 |
1/2/2018 |
1/3/2018 |
1/5/2018 |
1/7/2018 |
1/10/2018 |
Let's also say that we are looking at the data that we have from 12/1/2017 to 1/31/2018 (Let's assume these start and end dates are selected from an unbound form field). That means we have the following data gaps:
Date Gaps |
---|
12/1/2017 - 12/31/2017 |
1/4/2018 - 1/4/2018 |
1/6/2018 - 1/6/2018 |
1/8/2018 - 1/9/2018 |
1/11/2018 - 1/31/2018 |