+ Start a Discussion
ashish raiashish rai 

How to add 3 months on Date type field

Hi All,

I want to add 3 months on my date type field.For example if Date=30/11/2012 then the formula field should display value as 01/03/2012. I am using this formula which is working fine for day value <= 28.

 

If(year(datefield__c) < 10, Date(year(datefield__c),month(datefield__c)+3,day(datefield__c)),

Date(year(datefield__c)-1,month(datefield__c)+3-12,day(datefield__c)))

 

The above formula give me the formula field value as error for the Datefield value=30/11/2011. I want value should be 01/03/2012. Please help me on this.

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below formula for reference:

 

DATE(year( CustomDate__c )+ floor((month(CustomDate__c) + Add_Months__c)/12) + if(and(month(CustomDate__c)=12,Add_Months__c>=12),-1,0),if( mod( month(CustomDate__c) + Add_Months__c , 12 ) = 0, 12 , mod( month(CustomDate__c) + Add_Months__c , 12 )),min(day(CustomDate__c),

case( mod( month(CustomDate__c) + Add_Months__c , 12 ) , 1),9,30,4,30,6,30,11,30,2,28,31)))

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

prady-cmprady-cm

Not a easy thing to do in formula

 

Check this link

https://sites.secure.force.com/success/ideaView?id=08730000000BrQ2AAK

 

Look for james solution there

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below formula for reference:

 

DATE(year( CustomDate__c )+ floor((month(CustomDate__c) + Add_Months__c)/12) + if(and(month(CustomDate__c)=12,Add_Months__c>=12),-1,0),if( mod( month(CustomDate__c) + Add_Months__c , 12 ) = 0, 12 , mod( month(CustomDate__c) + Add_Months__c , 12 )),min(day(CustomDate__c),

case( mod( month(CustomDate__c) + Add_Months__c , 12 ) , 1),9,30,4,30,6,30,11,30,2,28,31)))

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer