How to extract date in dd-mm-yyyy format?

I am using JSON format data as training data. Simple things are working correctly.

Now I want to extract the date part from the data and I would like to use regex for that and I don’t want to hardcode all dates in training data.

Is this possible using regex? If possible, how?


  "backend": "spacy_sklearn",
  "path" : "./",
  "data" : "data/sitebot-data.json",

Ex. If the user enter “Show me something happening on 11-12-2018” then I should be abele to extract 11-12-2018.

Any help would be greatly appreciated.


You could build this by hand if you really needed to, but it would be way easier to use Duckling to extract your dates for you. Here’s the bit in the docs that tells you how to add it to your assistant. :slight_smile:


@mayur091193 You can use Duckling or python DateTime package to validate your date value according to your requirements.

I hope It will help you

def validate_date(
    value: Text,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any],
) -> Optional[Text]:
    """Validate date value."""
 #text = '2nd aug 2020'
        date = d.parse_time(value)
        Ducklingvalue = date[0]['value']['value']
        from_date = Ducklingvalue[0:4]
        current_text = 'today'
        current_date = d.parse_time(current_text)
        Current_date_Ducklingvalue = current_date[0]['value']['value']
        current_year = Current_date_Ducklingvalue[0:4]
        today = str(current_year)
        count = abs(int(from_date)-int(today))
        if count > 0 or count < 0:
            final_date = today+Ducklingvalue[4:10]
            final_date = Ducklingvalue[0:10]
    except Exception as e: 
        dispatcher.utter_message("Provide input in proper format. e.g. 17th sept.")
        return {'date': final_date}
1 Like