How can I send the call duration in seconds to my ...
# support
When I receive the call report, it comes in date and time format, but I would like to know how to convert it into seconds to see exactly how long the call lasted. Here is an example: startedAt 4 May 2024 10:46 endedAt 4 May 2024 10:46
Hi @Alex Contreras, I'm an AI assistant for Vapi. I'll analyze available sources and get back to you shortly.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Update Assistant]() * [Create Assistant]() * [List Calls]() * [Get Call]() -----------------------------
### Answer To calculate and send the call duration in seconds to your webhook, you would typically need to receive both the
timestamps for a call, calculate the difference in your server or webhook logic, and then convert that difference into seconds. Given the example timestamps you provided, here's a general approach in Python to calculate the duration in seconds:
Copy code
from datetime import datetime

# Example timestamps
started_at = datetime.strptime("4 May 2024 10:46", "%d %b %Y %H:%M")
ended_at = datetime.strptime("4 May 2024 10:46", "%d %b %Y %H:%M")

# Calculate duration in seconds
duration_seconds = (ended_at - started_at).total_seconds()

print("Call duration in seconds:", duration_seconds)
This script assumes that the
timestamps are in the format "day month year hour:minutes". Adjust the datetime format in
to match the format you receive. Please note, however, the actual implementation detail of sending this calculated duration to your webhook depends significantly on your server or webhook setup. You'll likely need to capture these timestamps from the call report data sent to your webhook, perform the calculation as shown above, and then include the calculated duration in the subsequent requests or processing logic within your system. Regarding the functionality directly within Vapi or its documentation, the specific details on capturing
timestamps and sending calculated durations are not directly covered in the provided information sources. Thus, implementing the calculation and sending logic would be a task for your server or webhook processing code based on the timestamps provided by Vapi's call report data.
Got it. Tagging @User for additional help.
Thanks for the follow-up, @Sahil. I'll get back to you soon.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [List Metrics]() * [Function Calling]() * [Update Assistant]() * [Create Assistant]() -----------------------------
### Answer Sorry, I wasn't able to find any information about your question.
Glad I could be helpful. Feel free to create a new thread with any new questions you may have.