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

slam

Well-known Member
Joined
Sep 16, 2002
Messages
915
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
 
I'm getting a #REF! on that - maybe because of my date format?
You might need to adjust the cell references to your start and end dates. Formatting shouldn't matter as long as it's a date type.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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?
If neither date is in 2024, the result should be 0.

Thanks!
 
Upvote 0
If neither date is in 2024, the result should be 0.

Thanks!
SO your first example is wrong then?


Book1
ABCDEF
1StartEndCalc StartCalc End
22018-01-012027-12-313650.002024-01-012024-12-31
32024-03-012024-03-313131.002024-03-012024-03-31
42023-12-202024-01-0222.002024-01-012024-01-02
52020-01-252020-05-010.002024-01-012024-05-01
62020-06-152026-07-150.002024-01-012024-07-15
72028-09-252030-08-060.002024-01-012024-08-06
Sheet1
Cell Formulas
RangeFormula
D2:D7D2=IF(AND(YEAR(B2)<>2024,YEAR(A2)<>2024),0,DATE(2024,MONTH(B2),DAY(B2))-IF(YEAR(A2)=2024,A2,DATE(2024,1,1))+1)
E2:E7E2=IF(YEAR(A2)=2024,A2,DATE(2024,1,1))
F2:F7F2=DATE(2024,MONTH(B2),DAY(B2))
 
Upvote 0
You might need to adjust the cell references to your start and end dates. Formatting shouldn't matter as long as it's a date type.

Did do that.... but gave it one more try, and now it's working (so put that down to user error - me :))

Excel Formula:
=SUMPRODUCT(--(YEAR(ROW(INDIRECT(S12&":"&T12)))=2024))

Thank you!!

Thank you to everyone. You are all amazing for the help you offer here!
 
Upvote 0
Glad you have a solution, but be aware that indirect is slow & volatile.
 
Upvote 1

Forum statistics

Threads
1,223,785
Messages
6,174,537
Members
452,571
Latest member
MarExcelTips

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