Hey everyone,
I’m running into a bit of a wall with an expression in Architect. I need to set a variable based on whether the current time is within business hours AND if it’s a weekday. The goal is to flag calls for WFM adherence tracking differently on weekends.
I tried using DateTimeDiff to check the time, but I’m not sure how to combine it with a day-of-week check in the same expression. Here’s what I have so far:
DateTimeDiff(Now(), "2024-01-01T09:00:00Z", "hours") > 0
This obviously doesn’t work because the date is hardcoded and it doesn’t account for the day of the week. I found GetDayOfWeek in the docs, but I can’t figure out the syntax to say “if day is not Saturday or Sunday”.
Is there a way to nest these? Or do I need to use a Data Action first? Any help would be great.
You’re overcomplicating it. DateTimeDiff is for duration, not state checking. For adherence logic, you usually want boolean checks, not math.
The docs for GetDayOfWeek say it returns an integer from 1 (Sunday) to 7 (Saturday). So you just check if it’s between 2 and 6.
For the time check, don’t use DateTimeDiff. Use GetHourOfDay or GetMinuteOfDay. It’s cleaner. Here’s how I set it up in my C# backend to generate the expression string for the Architect API, but the logic holds for manual entry too:
// This is the expression string you'd put in Architect
string adherenceExpression =
"(GetDayOfWeek(CurrDateTime()) >= 2 AND GetDayOfWeek(CurrDateTime()) <= 6) AND " +
"(GetHourOfDay(CurrDateTime()) >= 9 AND GetHourOfDay(CurrDateTime()) < 17)";
If you need to handle lunch breaks or specific shift patterns, you’ll need to nest more AND/OR blocks. But for simple weekday business hours, that’s it.
One gotcha: CurrDateTime() respects the timezone of the flow. If your flow runs in UTC but your agents are in Sao Paulo (like me), you need to adjust the hours or use ConvertTimeZone first. I’ve burned a lot of hours debugging that one.
// If timezone is an issue, use this instead
string adjustedExpression =
"(GetDayOfWeek(ConvertTimeZone(CurrDateTime(), 'America/Sao_Paulo')) >= 2)";
Check the timezone setting on your flow. That’s usually where the “it works in UI but not in API” bugs come from.
You might want to pause before deploying that GetDayOfWeek logic to production. It’s a bit brittle when you consider timezone shifts. The expression evaluates on the server side, which usually means UTC. If your agents are in London and you’re checking against local business hours, you’ll get false negatives during daylight saving transitions or if the system clock drifts.
I’ve seen adherence reports break because the day roll-over happened at midnight UTC instead of local midnight. A safer bet is to use DateTimeFormat with the specific timezone offset for your location, like GB-London. Then you can parse the full timestamp string to get the local day and hour.
It looks something like this:
DateTimeFormat(Now(), "yyyy-MM-dd HH:mm:ss", "GB-London")
This ensures the logic matches the agent’s actual clock. It’s more verbose, but it saves you from debugging compliance gaps later. You can then use Substring to pull the day part if you really need an integer check, or just compare the string directly.