I have two dates
- startdate : 12/26/2022
- enddate : 02-28-2023
if the start date is 1-15th day then the result should be the current month ex: mm-dd-yyyy[12-11-2022]
Then December 1st
if the start date is 16th-31st day then the result should be the current month EX: mm-dd-yyyy[12-22-2022]
Then January 1st.
if the EndDate is 1-15th day then the result should be the current month+1 EX: mm-dd-yyyy[02-11-2022]
Then January 31st
if the EndDate is 16-31sh day then the result should be the current month+1 EX: mm-dd-yyyy[02-20-2022]
Then Feb 28th
input start date result: December 1st
input end date result: Feb 28th
I am looking for difference in the months from startdate and enddate as per given if conditions
- startdate : 12/26/2022
- enddate : 02-28-2023 Expected Output/result : [2]
Can we do this in the formula field? I am able to do it in apex it worked but I was unable to do it in the formula field any help would be appreciated.
Formula field i tried:
IF(DAY(EndDate__c) <= 15,(MONTH(EndDate__c)),IF(DAY(EndDate__c) >= 16,(MONTH(EndDate__c)+1),NULL )) -
IF(DAY(StartDate__c) <= 15,(MONTH(StartDate__c)),IF(DAY(StartDate__c) >= 16,(MONTH(StartDate__c)+1),NULL ))
Final Output:
ROUND(((IF(DAY(Return_To_Work__c) <= 15, DATE( YEAR(Return_To_Work__c) ,
MONTH(Return_To_Work__c) -1,(DAY(Return_To_Work__c)-
DAY(Return_To_Work__c)+
28 + MOD(((MONTH(Return_To_Work__c) -1) +
FLOOR((MONTH(Return_To_Work__c) -1)/8)), 2) + MOD(2,
(MONTH(Return_To_Work__c) -1)) + 2 * FLOOR(1/(MONTH(Return_To_Work__c)
-1))))
,IF(DAY(Return_To_Work__c) >= 16,DATE( YEAR(Return_To_Work__c)
,MONTH(Return_To_Work__c),(DAY(Return_To_Work__c)-
DAY(Return_To_Work__c)+28 + MOD(((MONTH(Return_To_Work__c)) +
FLOOR((MONTH(Return_To_Work__c))/8)), 2) + MOD(2,
(MONTH(Return_To_Work__c))) + 2 *
FLOOR(1/(MONTH(Return_To_Work__c))))),NULL)) -
IF(DAY(First_Day_Of_Leave__c) <= 15, DATE( YEAR(First_Day_Of_Leave__c)
, MONTH(First_Day_Of_Leave__c) ,(DAY(First_Day_Of_Leave__c)-
DAY(First_Day_Of_Leave__c)+1)),IF(DAY(First_Day_Of_Leave__c) >=
16,DATE( YEAR(First_Day_Of_Leave__c)
,MONTH(First_Day_Of_Leave__c)+1,(DAY(First_Day_Of_Leave__c)-
DAY(First_Day_Of_Leave__c)+1)),NULL)))/30),0)