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
Manish.SinghManish.Singh 

Business Hour isWithin() function showing false

Hello everyone,
When I execute the following code from the anonymous window, it gave me the unexpected result. Please have a look,
Code-
datetime targetDate = Datetime.now();
Time tcurrentTime=targetDate.time();                
DateTime currentDateTime = datetime.newInstanceGmt(Date.today(), tcurrentTime);
string dayOfWeek = currentDateTime.format('EEEE');
Boolean isWithinBusinessHour = BusinessHours.isWithin('01m1H000000MbGw', currentDateTime);
System.debug('dayOfWeek '+dayOfWeek);
System.debug('isWithinBusinessHour '+isWithinBusinessHour);

Output-
User-added image

Business Hour-
User-added image
Expected output-
Boolean isWithinBusinessHour = BusinessHours.isWithin('01m1H000000MbGw', currentDateTime);
It must show "true" because current date exists in business hour.
any help would be appriciated
Thanks in advance!
Hara SahooHara Sahoo
I hope the currentDateTime is within 8 am - 5 Pm, the time when you are running the query and there are no holidays marked for the day when you run the script.