Calculate days between dates

(Black Rabbit Foot) #1

Hello, I started using your service and my delight is no limit. But, I can not make a calculation with the deduction of the number of days - between two dates.
On an example of my calculation:
{{Price.parsed_answer}} * 0.035 / 365 * {{days.parsed_answer}}
Now the value of “days”, I think and write manually, I would like to optimize this process and type only the end date:
{{Days.parsed_answer}} - {{Price.datetime}} = {{Price.parsed_answer}} * 0.035 / 365 * {{number of days between dates}}
How can I just do this?
Thank you very much for your attention

P.s.
Is it possible to shorten the calculation result to .00?
Now I use:

  1. Ask a Question: Validation - integer
  2. Number - Calculate
  3. Number - Format Number: {{calculate.result}} - Format: 0.00
  4. Send a Message: {{format.result}}
    Is it possible to do this as something simpler?
(Sarah Palombo) #2

I can’t see a way to simplify you steps 1-4 above.That’s the way i’d have used. Though there is a way to calculate the number of days between two dates

Here’s How: -

  • Format both of the date(s) using the Date & Time Service (Format Date) You need to * Add X (Capital X) in the format. This will change each date into seconds. (it’s easier to work back to days later). We’re adding X as follows:

  • You’ll then need to calculate those formatted dates. (make sure you use the results from each formatted date) just choose to format the {{yourfurthest date}}-{{yourclosest date}}. Of course you’re picking those results from the list using the XO icon. This will calculate the difference in seconds.

  • There’s 86400 seconds in a day, to get the calculation back to days. Just choose to Calculate using the {{resultabove}} /86400

In My example I used (25/06/2017)-(20/06/2017}) My results from those formatted dates here were =43200.
I calculate 43200/86400 which gives a result 5 (5 days difference between each date!)

Hope that helps!

Sarah

2 Likes
Limit the use of interactions per bot
Google Sheet > Update Row doesn't work
(Black Rabbit Foot) #3

This is genius. Everything works perfectly. I made a choice -
Fully manual branch and automatic, where you only need to specify the end date… But… how can I increase the bot’s time zone by {{new_message.datetime}} +3 hours?)

(Daniel Beckett) #4

If you need to set a specific time zone for your bot then this can be done from your profile area on the Flow XO website. For manual calculations you can offset the date & time by using +3h at the end of your date and time.

For example, you could have a question that asks the user to supply a date and time:

You would then have a Format Date action that uses the answer to the question and offsets the time by +3 hours:

{{ask_a_question.parsed_answer}} +3h

1 Like
(Ilaria Di Lecce) #5

Hello,
how can I calculate the difference in seconds between a date given by the user and todays date?

(Daniel Beckett) #6

Hi @Ilaria_Di_Lecce

This can be done by using a combination of the Date & Time Service and the Number service.

You would need to format the date using a custom format from the supported list here. There’s an option to format into seconds by setting it as ‘X’. If you were using a Catch-all trigger it would look something like this:

If you repeat that for the date provided by the user you can then use the Number service to calculate the difference between them.

1 Like