Time date use case

(Bryan Song) #1

Hi i would like to use the time date how do i use them? I want to ask

when will you like to travel from?

travel to?

calculate duration of stay

please help i need to code this for a demo tomorrow

(Joe Hatch) #2

You can use the attributes service to store the information and use it in your flow.

(Kellsey Shaw) #3

Hi Bryan,

Sadly, we don’t have a built-in service that can do this for you. :slight_frown:

You would need to look at using the Code service to calculate the difference between two dates.

What you could do instead is get the travel from date and ask the duration instead. Our Dates & Times allows you to calculate a date by adding to a starting date. So if I said I wanted to travel from 19 October 2016 for 7 days, it would calculate a date of 26 October 2016 :thumbsup:

(Bryan Song) #4

Any sample or example?

(Bryan Song) #5

Thanks Kellsey do you have a sample for that?

(Joe Hatch) #6

Hi @Bryan_Song

Did you read the available documentation here? It should make things a bit easier to understand, but I’ll give an example below:

On your bot, you want to ask a question “When would you like to travel from?” and your bot will be smart enough to understand common terms as listed in the documentation (e.g. next week, tomorrow, dd/mm/yyyy, next friday etc.)

Then you’re able to use this answer and store it as an attribute for future use (e.g. departure date).

If your next questions was ‘Travel to’ (I suggested rewording this, as travel to could mean the destination) you could make your life easier by asking “how many days would you like to travel for?” and then you could use
{{name_of_flow.depart_date}}+{{number_of_days}}d

What this does is take the initial date they’re trying to fly on and add X number of days as answered by the user - remember to format your date and time though otherwise you might get unpredictable outputs (by default it’s mm/dd/yyyy) and I’ve shared an example of how this works below:

Bot asks: Which date would you like to depart?
User answers: 11th November 2016

We can store 11th November 2016 as a departure date attribute.

Bot asks: How many days would you like to stay for?
User answers: 10 days.

We store 10 days as departure duration then using the date/time service again you’re able to do
{{departure_date}}+{{departure_duration}} and it will output the return date which you can also store.