Hi. I am trying to create a user-defined function in MySQL to calculate the expiration date based on a start date and a variable number of hours. The rub is that I need it to skip non-working hours. The function definition would look something like this:
CREATE FUNCTION xHoursToBusTime (hrs INT, fromDt DATETIME) RETURNS DATETIME
So, for example, if hrs = 15 and fromDt = '01/24/2010 16:05:00', the function would need to decide that the next working hour is '01/25/2010 08:00:00', subtract the time until 5pm (or 9 hours), leaving hrs = 6, then increment the day and add the remaining hours to fromDt. This would return the result, '01/26/2010 14:05:00'.
I've read that you can't have recursive functions so I'm not sure how to go about this. Plus, it will need to check a holiday table somewhere in the function and increment the day if there is a match. The whole thing gets kinda sticky!
Does anyone have any ideas? I'll settle for some pseudocode or anything that might help me solve this one.