Count the number of days between two dates that are in 2024

slam

Well-known Member
Joined
Sep 16, 2002
Messages
873
Office Version
  1. 365
  2. 2019
I have a date in column Q (Start Date) & a date in column R (End Date) that are formatted as DD-MMM-YYYY, i.e. 03-APR-2024. The dates range from 2018 to 2027.

I need to count the number of days that are between the two dates that are in 2024. Some examples of what I'd want the output to be:

01-JAN-2018 | 31-DEC-2027 = 365
01-MAR-2024 | 31-MAR-2024 = 31
20-DEC-2023 | 02-JAN-2024 = 2

I don't really care if it accounts for leap years.

Could I trouble someone for a magical formula for this?

For Office 365.

Thanks!
<3
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You can use the DATEDIF function. It doesn't show up in Excel's Intellisense, but it works. DATEDIF function - Microsoft Support

Excel Formula:
=DATEDIF(Start_date,End_date,"D")

I've been using that.... though if I just do =R2-Q2, it also defaults to days. The issue is I now need to only count the days that occur in 2024, and I'm not sure how to incorporate that.
 
Upvote 0
How about
Fluff.xlsm
ABC
1
201/01/201831/12/2027366
301/03/202431/03/202430
420/12/202302/01/20242
Sheet6
Cell Formulas
RangeFormula
C2:C4C2=MIN(B2,DATE(2024,12,31))-MAX(A2,DATE(2023,12,31))
 
Upvote 0
Try this formula:
Book1
ABCD
1
22018-01-012027-12-31365366.00
32024-03-012024-03-313131.00
42023-12-202024-01-0222.00
Sheet1
Cell Formulas
RangeFormula
D2:D4D2=DATE(2024,MONTH(B2),DAY(B2))-IF(YEAR(A2)=2024,A2,DATE(2024,1,1))+1
 
Upvote 0
Hi Fluff - thanks for the reply. I see it working in your example, but it is not in mine; as it is showing 366 as every result, regardless of dates. I trust this is due to my different date format. Is it possible to get it to work with DD-MMM-YYYY?

Nice to see it automatically works for leap years though.

Thanks!
 
Upvote 0
Here's my attempt :)
Book1
ABCD
11/1/1812/31/27366
23/1/243/31/2431
312/20/231/2/242
4
Sheet5
Cell Formulas
RangeFormula
C1:C3C1=SUMPRODUCT(--(YEAR(ROW(INDIRECT(A1&":"&B1)))=2024))
 
Upvote 1
Solution
Try this formula:
Book1
ABCD
1
22018-01-012027-12-31365366.00
32024-03-012024-03-313131.00
42023-12-202024-01-0222.00
Sheet1
Cell Formulas
RangeFormula
D2:D4D2=DATE(2024,MONTH(B2),DAY(B2))-IF(YEAR(A2)=2024,A2,DATE(2024,1,1))+1

This doesn't seem to be working when both dates are outside 2024. I.e., for 22-May-2021 to 31-Dec-2023 it is showing 366 when it should be showing 0.
 
Upvote 0
Here's my attempt :)
Book1
ABCD
11/1/1812/31/27366
23/1/243/31/2431
312/20/231/2/242
4
Sheet5
Cell Formulas
RangeFormula
C1:C3C1=SUMPRODUCT(--(YEAR(ROW(INDIRECT(A1&":"&B1)))=2024))

I'm getting a #REF! on that - maybe because of my date format?
 
Upvote 0
This doesn't seem to be working when both dates are outside 2024. I.e., for 22-May-2021 to 31-Dec-2023 it is showing 366 when it should be showing 0.
Not sure what you mean. It seems to work here: (I am using YYYY-MM-DD formats):
Edit: I understand.. will update in a second. Although I didn't understand from your question you wanted zeros if the last date was prior to 2024.
What if both dates are after 2024?
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,653
Members
449,111
Latest member
ghennedy

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