Develop With Data
Develop With Data

Reputation: 5

How do I get the day, month, and year from Twilio date object?

Working on a Twilio Autopilot bot that requires age authentication. Right now I'm getting the date from the user and storing as a twilio.DATE object. It is in the format of 2002-04-24. What I'd like to do is get this in the format of:

user_birth_year = 2002,
user_birth_month = 4,
user_birth_day = 24.

I'd like to do this so I can compare it with the time right now to process the "of age" logic. Does anyone know if there's an easy way to access the year, month, and day in twilio like there is in javascript?

Upvotes: 0

Views: 265

Answers (1)

philnash
philnash

Reputation: 73027

Twilio developer evangelist here.

The best thing to do here is to process the date in JavaScript and add the individual year, month and day to the Autopilot assistant's memory.

You can do this by returning a redirect action to a Twilio Function that can extract the date from the field it is saved to and break it up into the constituent parts. Then return a remember action that places the year, month and day into the assistant's memory. You can then either return further actions from the Function, or another redirect to a task defined within the assistant.

Upvotes: 1

Related Questions