Forum Discussion
AndrewPatricio
5 years agoQrew Member
I had to do something similar (calculate using working hours and not just regular hours). The way I did this was by creating a very complex set of variables and if statements that increased the hours to subtract depending on how to take into account the non-working hours. In my case this was in a single day so I only had to take into account an 8 hour work day. But you could do something similar using "DayofWeek" for your problem. It's brute force, but it works.
------------------------------
Andrew Patricio
------------------------------
------------------------------
Andrew Patricio
------------------------------
- JenHamilton_Tye5 years agoQrew TraineeI thought that might be the answer. I often feel like I'm making things more complex than they have to be, "WeekdayAdd" works so well on dates that I hoped there was an easier answer.
------------------------------
Jen Hamilton
------------------------------- DonLarson5 years agoQrew EliteJen,
Assuming:
- that you never exceed one weekend
- Deadlines are on the whole hour
- The amount of time you are going backwards is whole hours
Try this:
// Convert User Numeric Input to Duration in Hours
var duration SubHours =Hours([Hours]);
// Calculate Day of the Week from the Deadline Sunday = Day Zero, Saturday = Day Six
var number DeadlineDay =DayOfWeek(ToDate([Deadline]));
// Calculate the numerical Hour of the Day from the Deadline
var number DeadlineHour = Hour(ToTimeOfDay([Deadline]));
// Calculate Hours from Sunday
var duration DeltaSunday = Hours($DeadlineDay-1)*24+ Hours($DeadlineHour);
// If the hours to subtract is greater than the Delta to Sunday, subtract an extra 48 hours
var datetime Early= If( $DeltaSunday>$SubHours, [Deadline]-$SubHours, [Deadline]-$SubHours- Hours(48));
// Display the early date time stamp to the User
$Early
------------------------------
Don Larson
Paasporter
Westlake OH
------------------------------