correct-apricot
correct-apricot2y ago

is there a simple way to get the current date and time?

like if a user says "thursday" the assistant knows which thursday it is
1 Reply
W. Williams (SFT)
Something like this in a Javascript step:
function formatDate(date) {
const pad = (num) => (num < 10 ? '0' + num : num);
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
return `${days[date.getDay()]}, ${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
}

function getCurrentDate(offset) {
// Get the current date/time
let now = new Date();

// Convert local time to UTC, then add the offset and convert to milliseconds
let utc = now.getTime() + (now.getTimezoneOffset() * 60000);
let newDate = new Date(utc + (3600000 * offset));

// Format the date and time
return formatDate(newDate);
}

// Change -6 to your GMT offset
yourVoiceflowVarName = getCurrentDate(-6);
function formatDate(date) {
const pad = (num) => (num < 10 ? '0' + num : num);
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
return `${days[date.getDay()]}, ${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
}

function getCurrentDate(offset) {
// Get the current date/time
let now = new Date();

// Convert local time to UTC, then add the offset and convert to milliseconds
let utc = now.getTime() + (now.getTimezoneOffset() * 60000);
let newDate = new Date(utc + (3600000 * offset));

// Format the date and time
return formatDate(newDate);
}

// Change -6 to your GMT offset
yourVoiceflowVarName = getCurrentDate(-6);
This will format the date in the following format in your time zone: Friday, March 1, 2024

Did you find this page helpful?