You need to sign in to do that
Don't have an account?
![miss v miss v](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
adding months to dates
i have an old post on here (http://community.salesforce.com/sforce/board/message?board.id=custom_formula&message.id=4416)
where I was attempting to add 1 or 2 months to a date. For instance, if my date was 3/4/2010, I wanted to be able to add one month and get 4/4/2010.
there was a link to a page (successforce i think) that had a series of formulas that would allow me to do this. however, i need to be able to access this page again and it's gone.
does anyone know where this page is, or if there is an easier way to accomplish this now?
thanks,
miss v
We have a field in our organization that basically takes the duration of an event (entered in months), converts it to days and then adds it to the event start date to give us an event end date.
If you want to add days, you can do:
Event_Start_Date__c + ((365/12)* Event_Duration__c)
If we put numbers to it:
Event Start: 7/4/2010
Event Duration: 2 (months)
Event End: 9/2/2010
I hope this helps!
~Will
The real question is how do you want to handle the boundary conditions of going from 31st one month to 30th being the last day of the next (and even worst February)? The safest option is to follow the above advice and add 30 days to roughly add a month.
The alternative is to base a formula on breaking down the components of the date and reconstructing it afterwards:
e.g.
DATE( YEAR( SLAExpirationDate__c ) , MONTH(SLAExpirationDate__c) + 1 , DAY(SLAExpirationDate__c) )
But this is going to error if not a valid date (it only always works for days 1-28, and months 1-11) so you'll need to cater for the boundary conditions using IF statements.
This idea has a great solution in the comments:
Need the ability to add and subtract months and years in formula fields. https://sites.secure.force.com/success/ideaView?c=09a30000000D9xtAAC&id=08730000000BrQ2AAK
addMonths(Integer) method is worked for me
Image_Upload__c img = [select Start_Date__c from Image_Upload__c where id=: 'xxxxxxxxxxxxxx'];
system.debug('~~~~~~~~'+img.Start_Date__c);
system.debug('~~~~~~~~'+img.Start_Date__c.addMonths(6));
Output:
~~~~~~~~2012-07-01 00:00:00
~~~~~~~~2013-01-01 00:00:00 // Added with 6 months
Thanks,
Praveen Murugesan.