ShowAll Questionssorted byDate Posted
bhanu_prakash

# date of previos month

help me to write trigger if date is less than or equal to 10 , i need to upate previous month last date . if it is above 10 we need to update same day

ex: date : 04-Jun-17   output -- 31-may-17
ex: date  : 10-jun-17  output -- 31-may-17
ex: date   11-jun-17    output -- 11-jun-17

i tried this formula
IF(MONTH(Date__c) < 12,
IF(DAY(Date__c) > 10, Date__c, DATE(YEAR(Date__c), MONTH(Date__c)-1,30)),
IF(DAY(Date__c) > 10, Date__c, DATE(YEAR(Date__c) + 1, 1, 30)))

if input is 02-06-17 ,but iam getting output as  01-05-17   i need to be 31-05-17.
Best Answer chosen by bhanu_prakash
Ahmad J. Koubeissy
try this formula:
```IF(DAY(Date__c) > 10, Date__c,
DATE( YEAR( Date__c), MONTH ( Date__c), 1 ) - 1
)```
You dont need to check if the month is 12, you always want the last day of the previous month.

thanks for marking as best answer

### All Answers

Ahmad J. Koubeissy
i used ur formula on 02-06-17 and it returned 30-05-17
bhanu_prakash
yes, issue is that one that month end date is 31st its popoulating 30th .i need to modify that formula
Ahmad J. Koubeissy
try this formula:
```IF(DAY(Date__c) > 10, Date__c,
DATE( YEAR( Date__c), MONTH ( Date__c), 1 ) - 1
)```
You dont need to check if the month is 12, you always want the last day of the previous month.

thanks for marking as best answer

This was selected as the best answer
bhanu_prakash
thanks Ahmad