function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bhanu_prakashbhanu_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. KoubeissyAhmad 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. KoubeissyAhmad J. Koubeissy
i used ur formula on 02-06-17 and it returned 30-05-17
User-added image
bhanu_prakashbhanu_prakash
yes, issue is that one that month end date is 31st its popoulating 30th .i need to modify that formula
Ahmad J. KoubeissyAhmad 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_prakashbhanu_prakash
thanks Ahmad