Date variables - unable to calculate absolute exa...
# support
r
I'm using VAPI (https://vapi.ai/) to have a voice agent take discovery bookings of 30 minutes and add it to my Google Calendar. When a caller requests in upcoming day of week, the model is getting confused when converting day of week to exact date. For example on a call today, the user said
Copy code
Yeah. I'm available on Tuesday, by 12 30 PM.
and the system responded
Copy code
Hold on a sec. I have found an available slot. On Tuesday, November nineteenth. 2025 at 12 30 PM. Uh, does this time work for you?
However Tuesday is Nov 18 and not 19th. And the appointment was made on 19th Nov (Wed). The system prompt corresponding to appointment scheduling is as follows
Copy code
## Appointment Scheduling
     - When scheduling with appointment. Use the timezone "Australia/Adelaide". Also tell this explicitly to customer that you are dealing with Adelaide time.
          - Timezone: Australia/Adelaide.
          - Current date: {{ "now" | date: "%B %d, %Y", "Australia/Adelaide" }}
          - Current time: {{ "now" | date: "%I:%M %p", "Australia/Adelaide" }}
          - Day of week: {{ "now" | date: "%A", "Australia/Adelaide" }}
          - When the caller says “today/tomorrow/next Wednesday”, interpret relative to this now.
    - Appointment intent - Ask for a preferred date/time for a 30-minute discovery call in Australia central time. 
    - Use the calendar availability tool around their preference to find open 30-minute slots. Never make up availability, —always check first.
    - Offer slots only Monday–Friday, 08:00–17:00 Australia/Adelaide, starting on :00 or :30 minutes.
I could not find any internal tools that can be invoked for getting correct datetime. Without getting correct datetime any booking system cannot work.
c
Hi there, Thank you for your message. Our team is currently out of the office. We operate Monday through Friday, from 9:00 AM to 8:00 PM Pacific Standard Time (PST). We’ll get back to you as soon as possible during our normal business hours. If your message is urgent, please mark it accordingly or include “URGENT” in the subject line, and we’ll do our best to respond promptly. Warm regards, Vapi Customer Support Team
r
Hello @User any updates on this. This is URGENT as I'm not able to use the scheduling feature, if this is not solved
@User do you need any other data to reproduce?
@Vapi Support Bot are you able to explain how the error can be mitigated?
v
To mitigate the date calculation error, implement a backend function that converts day-of-week references to absolute dates before passing them to the Vapi assistant or calendar tool. For example, in Python:
Copy code
python
from datetime import datetime, timedelta

def next_weekday(target_weekday, tz_now):
    days_ahead = (target_weekday - tz_now.weekday() + 7) % 7
    if days_ahead == 0:
        days_ahead = 7
    return tz_now + timedelta(days=days_ahead)

# Usage: next_weekday(1, datetime.now())  # 1=Tuesday
Integrate this logic so your assistant always schedules for the correct date when a user says "Tuesday" or similar. This approach is recommended in the [appointment scheduling example documentation](https://docs.vapi.ai/assistants/examples/appointment-scheduling). Source: - [Appointment scheduling assistant example](https://docs.vapi.ai/assistants/examples/appointment-scheduling)
v
Message marked as helpful by @rbala! 🎉
r
Hi thank you for response. I had a look at the recommended link. I just want to clarify you want me to create a custom tool and expose it to the Agent?
c
You can either create a custom tool on a server to calculate date or you can use the variables. typically, using this variable resolves the issue with the date:
Copy code
The current date and time is {{"now" | date: "%A, %B %d, %Y, %I:%M %p", "America/Los_Angeles"}}
More information on this can be found on the documentation:
2 Views