[SalesForce] How to subtract months from a date field

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.

Best Answer

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