Hi I tried subtracting Business hours. But somehow it is not working properly. Below is the code snippet that I used.
date mydate = date.parse('11/13/2012');
Datetime dt =datetime.newInstanceGMT(mydate.year(), mydate.month(), mydate.day());
List <BusinessHours> bhList = [SELECT Id FROM BusinessHours WHERE IsDefault = true] ;
Datetime newDt = BusinessHours.addGMT(bhList[0].id, dt, -(1*24* 60 * 60 * 1000));
System.debug('====='+dt+'====='+dt.format('EEEE')+'=>>>=='+newDt+'===='+newDt.format('EEEE'));
System.debug('====='+dt+'===='+(double)BusinessHours.diff(bhList[0].id, newDt,dt)/(1 * 24 * 60 * 60 * 1000L));
System.debug('========='+(double)BusinessHours.diff(bhList[0].id, datetime.newInstanceGMT(2012,11,13),datetime.newInstanceGMT(2012,11,12))/(1 * 24 * 60 * 60 * 1000L));`enter preformatted text here`
Few assumptions in Business Hours: All days other than sunday and saturday, working hours is 24 hours and for sunday and saturday No hours.
Problem : The above code is returning 2012-11-11 00:00:00(Sunday) for 2012-11-13 00:00:00(Tuesday) and business hours difference for this two date is showing .796
Debug log of the above code :
12:08:51.033 (33130000)|USER_DEBUG|[5]|DEBUG|=====2012-11-13 00:00:00=====Tuesday=>>>==2012-11-11 00:00:00====Sunday 12:08:51.033 (33443000)|USER_DEBUG|[6]|DEBUG|=====2012-11-13 00:00:00====0.7916666666666666 12:08:51.033 (33753000)|USER_DEBUG|[7]|DEBUG|=========-0.7916666666666666
Please help.