Can you count the days between two dates with a formula

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
How do you count the number of days between two dates, entered into 2 separate cells using a formula in excel?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Review this

 
Upvote 0
Simple: =A1-B1, where the dates are in A1 & B1, respectively, though to exclude the end date, you'd need =A1-B1-1. Conversely, to include the start date, use =A1-B1+1.
 
Upvote 0
Once you have the number of days, is it possible to work out how many weekdays, Saturday's, Sunday's or public holidays are in that period. I am trying to make a spreadsheet that calculate a quote price for a period, with a start/end date and a start,/end time. There is difference price for the different types of days but also different prices for different times of the day.

Does anyone have any advice as to some direction with what method I should use to solve this problem?
 
Upvote 0
How about

Book1
ABCD
102/12/2019
228/12/2019
3DaysSunday'sSaturday'sweekdays
4273420
Sheet
Cell Formulas
RangeFormula
A4A4=A2-A1+1
B4B4=INT((WEEKDAY($A$1- 1)-$A$1+$A2)/7)
C4C4=INT((WEEKDAY($A$1- 2)-$A$1+$A2)/7)
D4D4=NETWORKDAYS(A1,A2)


More about WEEKDAY Function

 
Upvote 0
Thanks for that Dante, that is really helpful.

I did some testing with the above formulas and these are the variables I set
  • Start Date - 10/12/19
  • End Date - 14/12/19
The 10th is a tuesday and the 14th is a saturday

The networkdays function displays 4 which is correct but the function to work out the saturdays is 0. If I change the finish date to be the 15/12/19, the total number of sundays goes to 1 but the total saturdays remains at 0.

The formula I have to work out the number of saturdays is
VBA Code:
=INT((WEEKDAY($B$17- 2)-$B$17+$F17)/7)

The formula I have to work out the number of sundays is
Code:
=INT((WEEKDAY($B$17- 1)-$B$17+$F17)/7)
 
Upvote 0
The start date is in B17 and the end date is in F17
 
Upvote 0
Could someone explain this formula to me please as I don't understand how it works and if I did understand it, I could use it for some additional applications?

VBA Code:
    =INT((WEEKDAY($A$1- 1)-$A$1+$A2)/7)
 
Upvote 0
It is also strange that if I change the start date from 10/12/19 to the 9/12/19, the saturday counter increases to 1, but the 9/12/19 is a monday???
 
Upvote 0
Just got it to work I think using
VBA Code:
=INT((WEEKDAY($B$17- 3)-$B$17+$F17)/7)

But it was only by trial and error.

Could you explain why it worked Dante please?
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top