3

I'm making a bot that can take dinner reservations. When it asks for the users reservation time, I'd like the bot to populate my variable $dayoftheweek with the day of the week based on the date the user inputs. How would I be able to do that?

slot

here is my slot "If Found".

value Basically I'd like to know what "value" I could put in to get the day of the week populated.

data_henrik
  • 16,724
  • 2
  • 28
  • 49
larry walker
  • 123
  • 6
  • What does the user provide, a date or some text? Do you already have the date entity produced by WA? What definition of "day of week" do you use (ISO, US, ...)? – data_henrik Oct 10 '19 at 07:41
  • the user puts in a @sys-date, Watson normally formats it as YYYY-MM-DD. Then I'd like the value of the $daysoftheweek is able to take that date and determine the day of the week like "monday" for example. – larry walker Oct 10 '19 at 08:47

3 Answers3

2

The easiest would be to use the new system entities (currently in beta). Enable the beta in your skills options. Then, in your dialog node, assign the following:

Check for: @sys-data.day_of_week
save as: mydayofweek

Note that the day names are lower case.

data_henrik
  • 16,724
  • 2
  • 28
  • 49
2

You can use the method reformatDateTime of the expession language to get the day from @sys-date.

For example setting $dayofweek to

<? @sys-date.reformatDateTime('u') ?> 

will set $dayofweek to a value between "1" (Monday) and "7" (Sunday)

or setting $dayofweek to

<? @sys-date.reformatDateTime('E') ?> 

will set $dayofweek to a value between "Mo" and "Su"

TVK
  • 1,042
  • 7
  • 21
0

The value of @sys-date is stored as a string format "yyyy-MM-dd" e.g. "2016-11-21".

If you want to know what day of the week that date is, you can use the method reformatDateTime:

"<? @sys-date.reformatDateTime('EEEE') ?>"

Here all the posibles values of the method

So your node would look something like this.

Or in JSON format:

{
  "context": {
    "dayoftheweek": "<? @sys-date.reformatDateTime('EEEE') ?>"
  }
}

And here a small test of what would be stored in $dayoftheweek:

Watson: Hello. How can I help you?

User: Day of the week test

Watson: Tell me a date

User: September 13, 2019

Watson: Friday

Here is the JSON Skill for the test.

Community
  • 1
  • 1