Forum Discussion
karenlorr_uk
Aug 25, 2021Copper Contributor
Count days separated by month
Hi Say I have table with 2 dates (field1 & field2) 20/12/2020 & 10/01/2021 How would I show the datediff by month in a query e.g. Dec 20 = 12 Jan 21 = 10 Or if the dates were 28/08/2021 ...
Gustav_Brock
Aug 26, 2021Iron Contributor
You can use the query DaysMonthsDateRange found in \demos\Date.accdb at
https://github.com/GustavBrock/VBA.Date
DaysMonthsDateRange
Id DateStart DateEnd Year Month DateFrom DateTo Days
| 0 | 28-08-2021 | 02-10-2021 | 2021 | 8 | 28-08-2021 | 01-09-2021 | 4 |
| 1 | 28-08-2021 | 02-10-2021 | 2021 | 9 | 01-09-2021 | 01-10-2021 | 30 |
| 2 | 28-08-2021 | 02-10-2021 | 2021 | 10 | 01-10-2021 | 02-10-2021 | 1 |
However, an end date is normally not included in date interval calculations so, to have a count of 2 for September, you would need to add one day to the date of your Field2 and pass that to DateEnd.
DateEnd = DateAdd("d", 1, [Field2])