Lil Stinker
Board Regular
- Joined
- Feb 16, 2022
- Messages
- 151
- Office Version
- 2019
- Platform
- 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?
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?