Monday, August 6, 2018

How to add months to date field in salesforce using formula expression builder

If you want to add say 6 months to the date fields in salesforce,its not straightforward. Please see this example as to how to achieve it.

DATE( 
YEAR(start_date__c) + FLOOR( ( MONTH (start_date__c) + 6 - 1 ) / 12 ), 
MOD( MONTH (start_date__c) + 6- 1 + 
IF( DAY (start_date__c) > CASE( MOD( MONTH(start_date__c) +6- 1, 12 ) + 1, 
2, 28, 
4, 30, 
6, 30, 
9, 30, 
11, 30, 
31 ), 1, 0 ), 12 ) + 1, 
IF( DAY(start_date__c ) > CASE( MOD( MONTH(start_date__c ) +6 - 1, 12 ) + 1, 
2, 28, 
4, 30, 
6, 30, 
9, 30, 
11, 30, 
31 ), 
1, DAY(start_date__c ) 
)


No comments:

Post a Comment