How to use dates in a Dialogflow CX condition

1,054 views
Skip to first unread message

Mike Blyth

unread,
Mar 23, 2021, 7:28:51 PM3/23/21
to Dialogflow CX Edition users
I am brand new to Dialogflow CX and am having trouble figuring out how to use a date in a condition. I want to require that a birthdate be entered and be greater than 2000-01-01. I have tried 

    $intent.params.dob.resolved > 2005-01-01

with and without quotes, but it does not work (always false). I discovered that

    $intent.params.dob.original > "1/1/01"  [or "1/1/2000"]

is resolved as True for all dates, so that is of no help, plus it would restrict the input format. 

Is there a way that works?

Riel Airen Ponce

unread,
Apr 7, 2021, 5:51:15 PM4/7/21
to Dialogflow CX Edition users

To achieve your described use case, you can utilize the condition route or conditional response to return a response according to the condition. Here is a condition you may use:

$intent.params.birthdate.resolved.year > 2000 OR ($intent.params.birthdate.resolved.year = 2000 AND $intent.params.birthdate.resolved.month > 1) OR ($intent.params.birthdate.resolved.year = 2000 AND $intent.params.birthdate.resolved.month = 1 AND $intent.params.birthdate.resolved.day > 1)

Here are examples for your reference:

A. Using the condition in the Conditional Response

Conditional Respons.png

B. Using the condition as the Condition Route:
Condition Route.png

Please note that the birthdate parameter isn’t a string parameter. It is composed of year, month, and day sub-parameters so it is appropriate to utilize them for your use case. Also, note that dates are in ISO-8601 format. For more information, you can refer to the System Entities documentation.

Here are the following results using the condition defined in the conditional response:

1. When the user enters the same year but not January 1st

1.png

2. When the user enters an invalid date

2.png

3. When the user enters a previous date from 2000-01-01

3.png

4. When the user enters a valid date and latest from 2000-01-01

4.png

Reply all
Reply to author
Forward
0 new messages