0

How to subtract months from a date field:

I have a date field on opportunity, called: Current Term End date. I want to create a Formula field, which will subtract 3 month from Current Term End date and display result in numbers.

Current Term End date - 3 month = days left. 

Basically i am displaying, how many days left for that opportunity to close/update something like this.

4
  • are you considering today's date also for this calculation? Jun 4, 2017 at 20:14
  • Put your code whatever you have tried so far Jun 4, 2017 at 20:28
  • I tried like this. Get the date 3 month before current term end date by this : Current_Term_End_Date__c -((365/12) * 3). Then to calculate Number of days left (Formula field)= (Current_Term_End_Date__c) - (Current_Term_End_Date__c -((365/12) * 3)). Jun 5, 2017 at 3:55
  • edit your question and put this Jun 5, 2017 at 4:24

1 Answer 1

2

With formula fields, date artithemetic is done in days.

Example: MyDateField__c - 5 substracts 5 days.

To substract a conceptual month you could do MyDateField__c - 30 to subtract 30 days.

However, not every month is exactly 30 days, so if you need very accurate result you will need to consider either:

(a) complicated formula, or

(b) rely on apex to do the date calculation for you, such as in a trigger or have process builder call an invocable apex class whenever the record or field value changes.

Formula Functions

For reference, please see these documentation articles about date/time functions in formula fields:

Apex Methods

0

You must log in to answer this question.

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