Architect String to Date

Hello,

The Amazon Lex step returns variables that are all of type String.

In my case one of these variables is actually a date - for example 2019 10 2

I need to play back this variable as audio but in date format

I trying the MakeDateTime and ToDateTimebut without any real success.

Can this be done in Architect?

Thanks

ToDateTime requires the value to be in the form YYYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm]. Since your string doesn't look like that, you'll need to do string manipulation to pull out the year, month, day, etc and use the MakeDateTime function.

For example:

MakeDateTime(ToInt(Split(Task.originalString, " ")[0]), ToInt(Split(Task.originalString, " ")[1]), ToInt(Split(Task.originalString, " ")[2]))

You need to be certain of the format of the response; if the value comes back as "2019/10/2" the expression above will cause an error b/c when the string is split by a space there is only one entry. Could you use a lambda with your lex action to force the response into a specific format?

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.