Help with Month, Week, Daily formula

Lil Stinker

Board Regular
Joined
Feb 16, 2022
Messages
151
Office Version
  1. 2019
Platform
  1. Windows
I am using this crazy long formula to display a period of time between two dates on our invoices. It currently displays #m, #w, #d (number of months, number of weeks, number of days). The issue I have with what it displays, is if the time period comes out to one month and a few days, it displays 1m,0w,3d. Or a month long period it displays, 1m,0w,0d.

What I would like is for it to display 1m,3d if the calculation comes out to zero weeks. Or simply 1m, if it is just one month, no weeks and no days. I only know enough about Excel to be dangerous. Not enough to wrap my brain around custom formulas.

=IF(ISBLANK(C3),"", IF($E$1="[ Term ]","", IF($E$1="Months",(DATEDIF($A$5,$A$7-(MOD($A$5,1)>MOD($A$7,1)),"ym")&"m,"&INT(DATEDIF($A$5,$A$7-(MOD($A$5,1)>MOD($A$7,1)),"md")/7)&"w,"&MOD(DATEDIF($A$5,$A$7-(MOD($A$5,1)>MOD($A$7,1)),"md"),7)&"d"), IF($E$1="Weeks",ROUNDDOWN((DATEDIF($A$5,$A$7,"d")/7),2)))))

Cell E1 is a drop down box with the list "[ Term ], Months, Weeks" so depending on your selection, a different result will display.
Cell C3 refers to a quantity column.
Cell A5 = the start date
Cell A7 = the end date

Can anyone suggest a modification to the formula that can achieve the type of result I'm looking for?
 
@Peter, I afraid your formula in #6 may get trouble with end date in next year:
31-Dec-22 To 01-Mar-23: => "2m, -1w,5d"
Also, if E1 = "Weeks", => 8.57 (should be "8w,4d") although OP expect it to be week count in fraction, but I suggest it to be "#w,#d"

I would refer my solution:
Code:
=IF(OR($B2="",AND(E$1<>"Months",E$1<>"Weeks")),"",
SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(E$1="Months",DATEDIF($A$5,$A$7,"m")&"m,"&INT(($A$7-EDATE($A$5,DATEDIF($A$5,$A$7,"m")))/7)&"w,"&MOD($A$7-EDATE($A$5,DATEDIF($A$5,$A$7,"m")),7)&"d",
INT(($A$7-$A$5)/7)&"w,"&MOD($A$7-$A$5,7)&"d"),"0m,",""),"0w,",""),",0d",""))
Good catch, bebo! How in the world did you figure that out? I didn't come up with the original formula myself so I took for granted that it would work without any issue. Thanks for offering your solution. It appears to be much more accurate.
When it comes to the E1 = "Weeks" formula however, our company bills weekly differently than monthly which is why it differs from the month formula.

Thanks again!
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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