Hello sachinhere,
I put together an example using Date::Manip module as a possible complete solution to your problem.
Sample of solution bellow:
What you need to notice here is, for the module the default working (business) hours are between 08:00 am - 5:00 pm (1 hour lunch in between). If these times do not fit your criteria (e.g. you prefer start at 08:30 am and end 5:30 pm) you can modify them, read more on how to do it here BUSINESS CONFIGURATION VARIABLES.
Regarding the Adding the Mode options e.g. "business" explanation. This parameter that you can add on the DateCalc function is $mode. This parameter when you do date calculations can take 6 different options. Sample from the documentation:
Each $mode has a different ability and output. For example $mode exact will return only hours and seconds and not days/weeks/months/years. If you are wondering why you can read here EXACT, SEMI-EXACT, AND APPROXIMATE DATE/DELTA CALCULATIONS.
The calculations that you can do through this module are almost infinite, I tried to add the minimum possible modifications to resolve your problem. I would encourage you to read as much as possible the documentation to understand the output and how you can adjust it on your requirements (timezone, working hours, holidays etc...etc...).
Update: Maybe I miss understood your initial question. I was under the impression that you want to calculate the time between non working hours. If this is what you want the code above should work, in case you do not want to do that and you are only interested in calculating the time between working hours see bellow:
Update 2: Another "similar question" was raised some time ago see Calculating Number Of Pay Periods. On this thread apart from calculating the time between two days during business hours you can also calculate between time-zones see Re: Calculating Number Of Pay Periods (UPDATED).
I hope this helps, BR
Seeking for Perl wisdom...on the process of learning...not there...yet!
|