How can I reliably calculate correct dates by my a...
# ask-ai
p
How can I reliably calculate correct dates by my agent? I'm passing {{current_date_and_time}} in this format - DD Month YYYY, Day, HHMMSS AM/PM IST But the agent is not calculating the dates correctly for coming next days or coming monday, how do I prompt it to reliably calculate that?
✅ 1
t
Thanks for reaching out, Shriniket. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I see you’re passing
{{current_date_and_time}}
in the format "DD Month YYYY, Day, HHMMSS AM/PM IST" and the agent is giving incorrect results for relative date requests like “coming next days” or “coming Monday.” I’ll explain what you can change so the agent reliably computes correct dates and give a simple prompt pattern you can use. Why this is happening • Human-readable date/time formats (like "12 March 2026, Friday, 021500 PM IST") are often ambiguous for programmatic date arithmetic. LLMs can misinterpret day/month order, timezone labels, or the meaning of “next” vs “this” Monday. • Agents compute relative dates best when they are given an unambiguous, machine-readable current date (and timezone) to base arithmetic on. What to do (short version) • Pass the current date in a machine-readable ISO-like format such as
YYYY-MM-DD
(and optionally include time as
YYYY-MM-DDTHH:MM:SS±HH:MM
). • Also include the timezone or UTC offset explicitly. • Inject that exact date string into the agent’s system prompt or context so all date calculations use that anchor. Recommended format examples • Date only:
2026-03-12
• Date + time + offset:
2026-03-12T14:15:00+05:30
(ISO 8601 with offset) • If you want both human and machine formats (helpful for display + reliable calc), pass both: ◦
current_human: 12 March 2026, Friday, 02:15:00 PM IST
◦
current_iso: 2026-03-12T14:15:00+05:30
Example prompt pattern to give the agent 1. Put the machine-readable current date into the agent’s context: ◦ "Current date (ISO): 2026-03-12" ◦ "Current time (ISO): 2026-03-12T141500+05:30" 1. Give explicit instructions about how to interpret relative terms: ◦ "When the user asks for ‘tomorrow’, calculate date = current date + 1 day." ◦ "When the user asks for ‘next Monday’ or ‘coming Monday’, return the date for the next calendar Monday that is strictly after the current date (not the current date if it is already Monday)." 1. Ask the agent to always output both the interpreted plain-English result and the ISO date: ◦ "Answer like: ‘Event falls on Monday, March 15, 2026 — 2026-03-15’." Minimal system instruction example you can inject • "The current date/time is
2026-03-12T14:15:00+05:30
. Interpret relative phrases like ‘tomorrow’, ‘next Monday’, and ‘coming Friday’ using this anchor. For ‘next Monday’ return the next Monday strictly after the current date. For every response, provide both a human-friendly date and an ISO date in the form
YYYY-MM-DD
." Why include the ISO date in the agent reply • This gives you a guaranteed machine-readable output to use downstream (scheduling, comparisons, APIs), and you can display the human string to users. One more tip on “next” vs “this” • Clarify your business rule in the prompt: decide whether “next Monday” means the very next occurrence (strictly after today) or the nearest Monday (including today if today is Monday). State that rule explicitly in the instruction. If you want, I can: • Give you a concrete prompt template that you can drop into your agent and which will accept your
{{current_date_and_time}}
and convert it into ISO before asking the LLM to compute. • Provide a small snippet (pseudo-code) showing how to convert your current format to ISO when injecting context. Which would you prefer — the prompt template, or the conversion snippet? Sources: Building a Moviefone-style Theater Assistant | LiveKit Documentation | Context Variables | LiveKit Documentation, with interactive elements