My introduction to programming was mainly .NET languages, so working with dates was usually a breeze, but one thing I've noticed on Salesforce is that (in the formula box at least) doing calculations with dates tends to be far more difficult than it needs to be.

Can someone who has worked with Salesforce for a long time offer any insight into why when I want to add 18 months to a date, I have to break the date down, then check if there are enough months until the end of the year, then make sure the right amount of days are in the month, then blah blah etcetera before building the date back up?

Why is it that I can't just do Date_Field__c + DATE(0,18,0)?

  • 1
    It's a good idea to try looking at the API instead of making random guesses on how things work. salesforce.com/us/developer/docs/apexcode/Content/…
    – dphil
    Commented Jun 5, 2014 at 13:53
  • I wasn't referring to the API though, I was referring to formula fields.
    – Adam
    Commented Jun 5, 2014 at 14:02
  • Ahhh ok, I see. The whole bit about the programming and .NET threw me off.
    – dphil
    Commented Jun 5, 2014 at 14:04

1 Answer 1


Well, in apex you can just do:-

DateTime dt = DateTime.now().addMonths(18);

Might be worth having a look at https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_datetime.htm

You need to bear in mind that there is a distinction between date and datetime types.

  • From now on I may do most calculations using apex triggers, it's more conducive to the way I've been taught.
    – Adam
    Commented Jun 5, 2014 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .