Hour Calculation
Hello, I'm trying to calculate the amount of hours between two datetime fields only including times of operation and not including weekdays. I've thrown my brain against this for entirely too long and below is the spaghetti I've come up with. I know the request and response variable aren't working as I need. If anyone can offer advice or help cleaning up/making the code work, I'd appreciate it! Thank you!
var datetime StartD=[Date and Time of Request]; // Declaring Start Date - Days
var datetime EndD=[Date and Time of Response]; // Declaring End Date - Days
var timeofday SStart = ToTimeOfDay([Date and Time of Request]);
var timeofday EStart = ToTimeOfDay([Date and Time of Response]);
var timeofday SEnd = ToTimeOfDay([Date and Time of Request]);
var timeofday EEnd = ToTimeOfDay([Date and Time of Response]);
var datetime StartH=[Date and Time of Request]; // Declaring Start Date - Hours
var datetime EndH=[Date and Time of Response]; // Declaring End Date - Hours
var date SDate=ToDate($StartD); // Declaring SDate and Converting to Date
var date EDate=ToDate($EndD); // Declaring EDate and Converting to Date
var number NumberOfDays=WeekdaySub($EDate, $SDate); // Finding Intergers of Days between Start and End
var TimeofDay STime=ToTimeOfDay($StartD); //Declaring Start Time variable STime
var TimeofDay ETime=ToTimeOfDay($EndD); //Declaring End Time variable ETime
var timeofday Request = If((ToNumber(ToText($SStart)) < 8) , ToTimeOfDay(ToText(8)), (ToNumber(ToText($SStart)) > 8), ToTimeOfDay(ToText(16)),
ToTimeOfDay(ToText($SStart)));
var timeofday Response = If((ToNumber(ToText($SEnd)) < 8) , ToTimeOfDay(ToText(8)), (ToNumber(ToText($SEnd)) > 8), ToTimeOfDay(ToText(16)),
ToTimeOfDay(ToText($SEnd)));
var duration ttime = Abs($Request-$Response);
Hours(($NumberOfDays*12)+ToNumber(ToText($ttime))) // Returning a Duration from a number of Days
------------------------------
Kevin T
------------------------------