Convert date interval to a number

I have a field which is the result in days between 2 date fields.
The formula I use is: field(‘Date départ’) - field(‘Date arrivée’)
It returns a “Date interval” in days.

In another field I need to multiply these days by a daily fee to get an amount to pay for the customer.
When I try to use the function “tonumber” to convert the date interval into a number I have a message saying it doesn’t work because tonumber only converts text to numbers.
How can I convert this date interval to a number to be able to multiply it with a fee (which is a number already)?

BR
Nicolas

1 Like

Hi Nico,

You can use the function date_diff for this.

date_diff('dd',field('Departure'),field('Arrival'))

The ‘dd’ ensures that the difference is expressed in a number of days. The other arguments are the dates that you want to use to calculate the difference. This function returns a number that you can use in other formula’s.

Regards
Frederik

1 Like

Thanks Frederik,

It works. But I had to swap the departure and arrival date in the script or it would give me a negative number.
date_diff(‘dd’,field(‘Date arrival’),field(‘Date departure’))

BR
Nicolas