# Issue: Inconsistent business-hours detection near midnight boundary

**URL:** <https://community.retellai.com/t/issue-inconsistent-business-hours-detection-near-midnight-boundary/3449>\
**Category:** Support Help\
**Tags:** bug\
**Created:** [July 31, 2026, 8:24pm UTC](https://community.retellai.com/t/issue-inconsistent-business-hours-detection-near-midnight-boundary/3449 "2026-07-31T20:24:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lahariyalavarthy](https://yyz2.discourse-cdn.com/flex008/user_avatar/community.retellai.com/lahariyalavarthy/32/2450_2.png) [@lahariyalavarthy](https://community.retellai.com/u/lahariyalavarthy)\
**Post date:** [July 31, 2026, 8:24pm UTC](https://community.retellai.com/t/issue-inconsistent-business-hours-detection-near-midnight-boundary/3449/1 "2026-07-31T20:24:06Z")

</div>

Our agent uses a dynamic variable for the current time in New York ex: {{current\_time\_America/New\_York}}. The system prompt tells the LLM to compare this against our hours (open 2 PM–2 AM daily) to decide OPEN or CLOSED.

**Problem:** This works most of the time, but is inconsistent specifically around the 2 AM boundary — on some calls it correctly says CLOSED, on other calls at roughly the same time it says OPEN. Same prompt, same time of night, different result.

**Our understanding:** the LLM is doing the AM/PM comparison itself each time as part of its reasoning, rather than following a fixed calculation, so it’s not deterministic.

**Question:** Is there a recommended, native way in Retell to do a reliable open/closed time-window check, rather than relying on the LLM to compare the dynamic variable against a schedule in the prompt?

 ![image](https://canada1.discourse-cdn.com/flex008/uploads/retell1/original/2X/3/34b49f734eaccfea723703d2929c51ffa7134708.png)

---

<div class="post-metadata">

**Author:** ![Shah-Fazal](https://yyz2.discourse-cdn.com/flex008/user_avatar/community.retellai.com/shah-fazal/32/2522_2.png) [@Shah-Fazal](https://community.retellai.com/u/Shah-Fazal)\
**Post date:** [July 31, 2026, 9:30pm UTC](https://community.retellai.com/t/issue-inconsistent-business-hours-detection-near-midnight-boundary/3449/2 "2026-07-31T21:30:37Z")

</div>

Hey @lahariyalavarthy Could you please share your Agent ID and this Call ID? This will help us investigate the issue further.

Thank You

---

<div class="post-metadata">

**Author:** ![lahariyalavarthy](https://yyz2.discourse-cdn.com/flex008/user_avatar/community.retellai.com/lahariyalavarthy/32/2450_2.png) [@lahariyalavarthy](https://community.retellai.com/u/lahariyalavarthy)\
**Post date:** [August 1, 2026, 1:37am UTC](https://community.retellai.com/t/issue-inconsistent-business-hours-detection-near-midnight-boundary/3449/3 "2026-08-01T01:37:05Z")

</div>

Hi Shah,  
Thanks for replying.

Here is the agent ID: agent\_9ea157742139b663dd855932ef  
Here are few call id’s:  
call\_e2626b305977211f34d3354c531  
call\_8b799e2bbc36196fda654567a38  
call\_38ebc4dd9b8b483333f03fa79c8

---

<div class="post-metadata">

**Author:** ![Shah-Fazal](https://yyz2.discourse-cdn.com/flex008/user_avatar/community.retellai.com/shah-fazal/32/2522_2.png) [@Shah-Fazal](https://community.retellai.com/u/Shah-Fazal)\
**Post date:** [August 1, 2026, 1:19pm UTC](https://community.retellai.com/t/issue-inconsistent-business-hours-detection-near-midnight-boundary/3449/4 "2026-08-01T13:19:28Z")

</div>

Hey @lahariyalavarthy Checking it with the team.

---

<div class="post-metadata">

**Author:** ![Shah-Fazal](https://yyz2.discourse-cdn.com/flex008/user_avatar/community.retellai.com/shah-fazal/32/2522_2.png) [@Shah-Fazal](https://community.retellai.com/u/Shah-Fazal)\
**Post date:** [August 3, 2026, 1:06pm UTC](https://community.retellai.com/t/issue-inconsistent-business-hours-detection-near-midnight-boundary/3449/5 "2026-08-03T13:06:17Z")

</div>

Hello @lahariyalavarthy The {{current\_time\_America/New\_York}} dynamic variable does expand to the right timezone-aware string, but everything after that (parsing “12:20 AM” and deciding whether it sits inside a 2 PM to 2 AM window that crosses midnight) is the LLM reasoning in free text, and that isn’t deterministic near the boundary. That’s exactly why you see the same-minute flip in your call sample.

The reliable pattern is to compute OPEN or CLOSED **outside** the LLM and pass the answer in as a variable. Two native options that fit your setup:

**Option 1: Pre-call inbound webhook (recommended for your single-prompt agent).** In the workspace inbound webhook, compute open\_status (“OPEN” or “CLOSED”) in your own code using the current time in America/New\_York, then return it under retell\_llm\_dynamic\_variables. Your prompt then reads {{open\_status}} directly instead of doing the math, so the LLM only needs to state the answer. Docs on dynamic variables and where they’re supported: [Dynamic variables: personalize Retell agent calls - Retell AI](https://docs.retellai.com/build/dynamic-variables)

**Option 2: Code Tool at the start of the call.** Add a Code Tool to the agent and instruct it to call the tool on the very first turn to set open\_status. The tool receives the dynamic variables via the dv object and returns fields you can store as new dynamic variables. This keeps everything inside Retell (no webhook infra needed), with the caveat that the LLM has to invoke the tool early, so gating the greeting on it helps. Docs: [Run JavaScript in Retell agents with Code Tool](https://docs.retellai.com/build/single-multi-prompt/code-tool)  
If you’re open to it, migrating this agent to a Conversation Flow lets you add a Code Node at the entry point that runs unconditionally before any LLM turn, which is the most deterministic version of Option 2. Docs: [Run JavaScript in a Retell conversation flow with Code node](https://docs.retellai.com/build/conversation-flow/code-node)

Whichever path you pick, rewrite the prompt so it stops comparing times and instead says something like: “If {{open\_status}} is CLOSED, tell the caller we’re closed and offer to take a message; if OPEN, greet normally.” That removes the AM/PM reasoning entirely, which is what’s flipping.

Thank You

---

<div class="post-metadata">

**Author:** ![lahariyalavarthy](https://yyz2.discourse-cdn.com/flex008/user_avatar/community.retellai.com/lahariyalavarthy/32/2450_2.png) [@lahariyalavarthy](https://community.retellai.com/u/lahariyalavarthy)\
**Post date:** [August 3, 2026, 5:18pm UTC](https://community.retellai.com/t/issue-inconsistent-business-hours-detection-near-midnight-boundary/3449/6 "2026-08-03T17:18:41Z")

</div>

Thanks for the input Shah

I will try this and let you know
