How to extract current date in watson conversation
Asked Answered
Q

4

5

I need to create a condition, in Watson Conversation dialog model, like this:

if "today's date" < 04-15-2017 do something. else do something else.

I prefer not asking the user for current date and save it.

I tried many ways but they don't work, I also tried to output the date (doesn't work):

{
  "context": {
    "currdate": "@sys-date:today"
  },
  "output": {
    "text": {
      "values": [
        "here it is $currdate"
      ],
      "selection_policy": "sequential"
    }
  }
} 
Quinine answered 3/4, 2017 at 14:31 Comment(1)
Your question is confusing. But, <? @sys-date ?> outputs the current dateUnscramble
A
6

I'm not sure about that, but with all tests I've tried, if user dont type today or something, Watson dont recognize, but, I believe with code we can do something. Probably someone work with IBM Watson will answer you correctly.

But, in my basic knowledge:

Try use now() in condition and save the date inside context variable.

The return is:

yyyy-MM-dd HH:mm:ss

Use your code to get the context variable and get just the date... after you can make conditions...

JSON Example:

{
  "context": {
    "dateHour": "<? now() ?>"
  },
  "output": {
    "text": {
      "values": [
        "Now is $dateHour."
      ],
      "selection_policy": "sequential"
    }
  }
}

I'm study all documentation about System entities within Watson and I dont see anything about extract the data if user dont request, but, how I say, probably someone work at IBM will answer, I'm just trying help you with my basic knowledge.

Check the Documentation about this entitie @sys-date now() here.

Ascend answered 3/4, 2017 at 16:54 Comment(0)
C
3

She's right, you'll need application code to grab the current date and time and pass it through as context. So far, all our system entities and efforts are around understanding what the user says, so if they don't say today, we won't know that its important. Theoretically I think you could just have your application pass through 'today' at the end of the user's sentence or something and that would run it through the processing pipeline and give you today's date, but might be a weird user experience.

Candide answered 3/4, 2017 at 22:0 Comment(0)
B
2

If you use now() then you can reformat it to get it to work.

I store the date I want to compare it against in $date, in your case "date": "04-15-2017", then use the following:

To see if the date is in the future use: now().reformatDateTime('dd-MM-yyyy').before($date)

If the past: now().reformatDateTime('dd-MM-yyyy').after($date)

You can read up on reformatDateTime here. It uses standard JAVA date string formatting rules which you can find here.

Barsky answered 11/7, 2017 at 18:0 Comment(1)
Is there a way to extract month or year from the sys-date?Musk
A
0

I had the same problem today, to solve it I used now(), it returns the current date. Set a context variable on the first conversation node:

{
  "output": {},
  "context": {
   "date": "<? now().reformatDateTime('dd-MM-yyyy') ?>"
  }
}

The context variable will return the current date in the format: "dd-MM-yyyy".

You can edit the format using reformatDateTime in different ways. Access the documentation: DOC Ibm Watson

Approbation answered 9/3, 2023 at 19:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.