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.

  • are you considering today's date also for this calculation? – Santanu Boral Jun 4 '17 at 20:14
  • Put your code whatever you have tried so far – Santanu Boral Jun 4 '17 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)). – Archita patnaik Jun 5 '17 at 3:55
  • edit your question and put this – Santanu Boral Jun 5 '17 at 4:24
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.