I am trying to parse a date slot in an interaction to find out the “weekday” of that date. In my project, I get the date input using a slot, which is assigned to a global variable.
I am trying to parse the global variable using the “code” block - but I find out that DATE slot is taking even string and any input practically. So I am not able to parse it…
My intention is to get the date as input from the user and then figure out “day” of that "date’ - make alexa speak that “day” as output.
Hi @krishchandru, you can use this code in the code block to get the weekday (alexadate variable is the variable you’ve mapped the user input with the Amazon.Date slot):
var tDate = new Date(alexadate);
theWeekDay = tDate.toLocaleDateString(‘en-US’, { weekday: ‘long’});
1 Like
Thanks @Nicolas .
For some reasons the options past wasn’t taking getting recognized when I combined. So, I assigned the same in a variable and gave it as input for the function. It worked
This is the snippet I used.Thanks for your help
var tDate = new Date(theDate);
var options = { weekday: “long” };
theWeekday = tDate.toLocaleDateString(“en-US”,options);
1 Like