Ilyass
Ilyass3mo ago

Access to CURRENT date and time

Hey, I want that my agent have access to the exact date and time for each conversation because when someone asks, ‘Where are you?’ the AI has to ask what time it is each time to provide the information. So I tried the code that you gave us some months ago but it's not working for me. Does someone have a solution to fix that ? (For french time btw) Thank you!
No description
3 Replies
majinnboo
majinnboo3mo ago
current date and time for Paris is lundi 29 septembre 2025 à 13:30:35 UTC+2 and here is the voice-flow javascript const now = new Date(); // Explicitly set the timeZone to Paris (France) Time. const optionsParis = { timeZone: 'Europe/Paris', // Paris (France) Time identifier // DATE Options weekday: 'long', // e.g., "lundi" year: 'numeric', month: 'long', // e.g., "septembre" day: 'numeric', // TIME Options hour: 'numeric', minute: 'numeric', second: 'numeric', // Locale and Time Zone Name timeZoneName: 'short' // e.g., "CEST" }; // This forces the date and time to be displayed according to the Paris Time Zone. // Using 'fr-FR' locale for typical French formatting (e.g., "lundi 29 septembre 2025 à 13:27:12 CEST"). var dateTimeParis = now.toLocaleString('fr-FR', optionsParis); console.log(Current Paris (France) Date and Time: ${dateTimeParis}); Variable to create in voiceflow would be {dateTimeParis}
Ilyass
IlyassOP3mo ago
hey thank you for your help ! But it's not working for me, maybe i'm doing something wrong?
W. Williams (SFT)
@Ilyass here you go:
const TZ = 'Europe/Paris'

const localDateTime = new Intl.DateTimeFormat('fr-FR', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: true,
timeZone: TZ
}).format(new Date())

// IMPORTANT: Create a VF variable first (whatever you want) and enter it bellow where I used vfDateTime var.

vfDateTime = localDateTime
const TZ = 'Europe/Paris'

const localDateTime = new Intl.DateTimeFormat('fr-FR', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: true,
timeZone: TZ
}).format(new Date())

// IMPORTANT: Create a VF variable first (whatever you want) and enter it bellow where I used vfDateTime var.

vfDateTime = localDateTime
NOTE: That will output DD/MM/YYY HH:MM:SS AM/PM - if you want 24 hour instead, change hour12 to false. Also, you can break the date and time apart removing the vfDateTime line above and replacing it with the following:
const [datePart, timePart] = localDateTime.split(',')

// Again, create the VF vars first

vfDate = datePart
vfTime = timePart
const [datePart, timePart] = localDateTime.split(',')

// Again, create the VF vars first

vfDate = datePart
vfTime = timePart

Did you find this page helpful?