You need to sign in to do that
Don't have an account?
Rahul63
Formula field to convert Date values including leap year
We have 3 fields Ex_Period_End_Date__c (DataType Date) and Contract_Notice_Exclusivity_months__c (DataType Number), Exclusivity_Date__c (Formula field).
Our requirment is Exclusivity_Date__c = Ex_Period_End_Date__c - Contract_Notice_Exclusivity_months__c
By using formula feild i wrote below code, it works for addition i.e, Ex_Period_End_Date__c + Contract_Notice_Exclusivity_months__c
if(AND( NOT( ISBLANK(Ex_Period_End_Date__c) ),NOT( ISBLANK(Contract_Notice_Exclusivity_months__c ) )),DATE (
/*YEAR*/
YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c - 1)/12),
/*MONTH*/
CASE ( MOD ( MONTH ( Ex_Period_End_Date__c )+Contract_Notice_Exclusivity_months__c, 12 ),0,12,MOD ( MONTH ( Ex_Period_End_Date__c )+Contract_Notice_Exclusivity_months__c, 12 )),
/*DAY*/
MIN ( DAY ( Ex_Period_End_Date__c ),
CASE ( MOD ( MONTH ( Ex_Period_End_Date__c )+Contract_Notice_Exclusivity_months__c,12 ) ,9,30,4,30,6,30,11,30,2,
/* return max days for February dependent on if end date is leap year */ IF ( MOD ( YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c)/12) , 400 ) = 0 || ( MOD ( YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c)/12) , 4 ) = 0 && MOD ( YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c)/12) , 100 ) <> 0
)
, 29,28)
,31 ) ))-1,
null)
The above snippet works for addition but our logic changed to substraction, can any one help out
Regards,
Rahul
Our requirment is Exclusivity_Date__c = Ex_Period_End_Date__c - Contract_Notice_Exclusivity_months__c
By using formula feild i wrote below code, it works for addition i.e, Ex_Period_End_Date__c + Contract_Notice_Exclusivity_months__c
if(AND( NOT( ISBLANK(Ex_Period_End_Date__c) ),NOT( ISBLANK(Contract_Notice_Exclusivity_months__c ) )),DATE (
/*YEAR*/
YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c - 1)/12),
/*MONTH*/
CASE ( MOD ( MONTH ( Ex_Period_End_Date__c )+Contract_Notice_Exclusivity_months__c, 12 ),0,12,MOD ( MONTH ( Ex_Period_End_Date__c )+Contract_Notice_Exclusivity_months__c, 12 )),
/*DAY*/
MIN ( DAY ( Ex_Period_End_Date__c ),
CASE ( MOD ( MONTH ( Ex_Period_End_Date__c )+Contract_Notice_Exclusivity_months__c,12 ) ,9,30,4,30,6,30,11,30,2,
/* return max days for February dependent on if end date is leap year */ IF ( MOD ( YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c)/12) , 400 ) = 0 || ( MOD ( YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c)/12) , 4 ) = 0 && MOD ( YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c)/12) , 100 ) <> 0
)
, 29,28)
,31 ) ))-1,
null)
The above snippet works for addition but our logic changed to substraction, can any one help out
Regards,
Rahul