+ Start a Discussion
Mani Cube84Mani Cube84 

Previous working date based on the BusinessHours

Hi
 
I need to find out the previous working date based on the BusinessHours .
 
Example

 
Order Due Date : Sunday, March 10, 2013

 
I need to get its previous working date which would be Friday, March 08,2013. 

 
Also I want to make sure that if Friday was an holiday then it should return me Thursday, March 07,2013. 

 
I have already looked at the business hours class  (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_businesshours.htm)
 
I was able to get the next buisiness day but not the previous buiseness day.
 
This is very urgent, I will appreciate if some one can provide me sample code for this.
 
Thanks
Ahmad J. KoubeissyAhmad J. Koubeissy
You can created two formula fields.

The first one:
Due_Date_Name (Type = Text).: to get the name of the current day, this one wont be visible on the layout
 
CASE( MOD( Order_Due_Date__c - DATE( 1900, 1, 7 ), 7 ), 0, "Sunday", 1, "Monday", 2, "Tuesday", 3, "Wednesday", 4, "Thursday", 5, "Friday", "Saturday" )


The second one:
Previous Working Day (Type=CheckBox): it checks if the was on saturday or sunday (not holiday) .
IF(Due_Date_Name ='Sunday',Order_Due_Date__c -2,Order_Due_Date__c -1)


If this solves your problem, kindly set as best answer. thanks
Mani Cube84Mani Cube84
Thanks for the response,  we are going through triggers and we are involving businesshours in this scenario as we have different users with differnt countries with thier countries (public/custom) holidays, we have use consider this also in this, how to achieve it using triggers..