Business hours is set to 7 AM to 7 PM
Mon to Fri
, Time Zone (GMT-05:00) Eastern Standard Time (America/New_York).
I need to simply add 5 working days from Current Date in order to calculate the target Date. I simply used BusinessHours.add
API.
Long bMilliSec = 5*12*60*60*1000;
System.debug('LONG VALUE :: '+bMilliSec);
Date startDate = Date.today();
DateTime startDateTime = DateTime.newInstance(startDate.year(), startDate.month(), startDate.day());
BusinessHours bh = [SELECT Id,Name,IsActive,IsDefault,MondayEndTime,MondayStartTime
FROM BusinessHours
WHERE Name = 'ZZZZZZ'];
DateTime businessEndDateTime = BusinessHours.add(bh.Id,startDateTime,bMilliSec);
System.debug('########## :: '+businessEndDateTime);
The below 2 days are holidays:
- 2/14/2018 All Day
- 2/12/2018 All Day
Why would I get a result of 22-Feb-2018 instead of 21-Feb-2018?
Some testing around this..
I created an Adhoc Request (for estimated completion date) is 2 days which should be 2/14/2018 but instead it’s displaying 2/13/2018. I created a content request,(for estimated completion date) is 2 days is 5 days which should be 2/19/2018 but instead it’s displaying 2/21/2018.
Some Crazy Calculations are happening
- if I add 2 days = 2018-02-17 00:00:00
- if I add 3 days = 2018-02-20 00:00:00
- If I add 4 days = 2018-02-21 00:00:00
- If I add 5 days = 2018-02-22 00:00:00
Datetime.now()
instead of your current approach to gettingstartDateTime
. – Adrian Larson♦ Feb 12 '18 at 16:01UserInfo.getTimeZone()
of the user running the Apex? – Daniel Ballinger Feb 13 '18 at 0:09