You’re on the right track. The issue is that DATETIME_DIFF() formula returns whole integers for any unit specifier, so simply trying to use a round up or similar won’t work.
What we can do is use the time difference in a calculation, something that does return decimals, and then format our output to integer.
So if we instead of days, ask the formula to calculate the hour difference, add 24 hours (instead of 1 day) and devide that by 24, we can now get outputs with decimals if we want.
You’re on the right track. The issue is that DATETIME_DIFF() formula returns whole integers for any unit specifier, so simply trying to use a round up or similar won’t work.
What we can do is use the time difference in a calculation, something that does return decimals, and then format our output to integer.
So if we instead of days, ask the formula to calculate the hour difference, add 24 hours (instead of 1 day) and devide that by 24, we can now get outputs with decimals if we want.
I hope that all made sense, English not being my native language and all.
First of all, many thanks for your help.
it works very well wen the hour of arrival is higher than the hour of depart. in the opposite this don’t work so well !
First of all, many thanks for your help.
it works very well wen the hour of arrival is higher than the hour of depart. in the opposite this don’t work so well !
Welcome to the Airtable community!
To ensure that the time does not influence the calculation you can use a combination of DATETIME_PARSE and DATETIME_FORMAT
Try this formula:
IF(
AND({Date departure}, {Date arrival}),
DATETIME_DIFF(
DATETIME_PARSE(
DATETIME_FORMAT({Date arrival}, "YYYY-MM-DD"),
"YYYY-MM-DD"
),
DATETIME_PARSE(
DATETIME_FORMAT({Date departure}, "YYYY-MM-DD"),
"YYYY-MM-DD"
),
'days'
) + 1
)
Note that you might still have issues due to timezones. In this case, I recommend using SET_TIMEZONE
IF(
AND({Date departure}, {Date arrival}),
DATETIME_DIFF(
DATETIME_PARSE(
DATETIME_FORMAT(
SET_TIMEZONE({Date arrival}, "Europe/Lisbon"),
"YYYY-MM-DD"
),
"YYYY-MM-DD"
),
DATETIME_PARSE(
DATETIME_FORMAT(
SET_TIMEZONE({Date departure}, "Europe/Lisbon"),
"YYYY-MM-DD"
),
"YYYY-MM-DD"
),
'days'
) + 1
)
Note that this will only affect the formatting of the number. If you use the number in a different formula, the decimal value will be used. Also, the formatting will round the number, and some values will round down instead of up.
Note that this will still have issues if the time is less than a full hour. For example, if the duration is 24 and a quarter hours, you will get one day instead of two.
Dear Kuovonne and momentsgoneby80. It Works very well . Many thanks for your Help :partying_face: .
Welcome to the Airtable community!
To ensure that the time does not influence the calculation you can use a combination of DATETIME_PARSE and DATETIME_FORMAT
Try this formula:
IF(
AND({Date departure}, {Date arrival}),
DATETIME_DIFF(
DATETIME_PARSE(
DATETIME_FORMAT({Date arrival}, "YYYY-MM-DD"),
"YYYY-MM-DD"
),
DATETIME_PARSE(
DATETIME_FORMAT({Date departure}, "YYYY-MM-DD"),
"YYYY-MM-DD"
),
'days'
) + 1
)
Note that you might still have issues due to timezones. In this case, I recommend using SET_TIMEZONE
IF(
AND({Date departure}, {Date arrival}),
DATETIME_DIFF(
DATETIME_PARSE(
DATETIME_FORMAT(
SET_TIMEZONE({Date arrival}, "Europe/Lisbon"),
"YYYY-MM-DD"
),
"YYYY-MM-DD"
),
DATETIME_PARSE(
DATETIME_FORMAT(
SET_TIMEZONE({Date departure}, "Europe/Lisbon"),
"YYYY-MM-DD"
),
"YYYY-MM-DD"
),
'days'
) + 1
)
Note that this will only affect the formatting of the number. If you use the number in a different formula, the decimal value will be used. Also, the formatting will round the number, and some values will round down instead of up.
Note that this will still have issues if the time is less than a full hour. For example, if the duration is 24 and a quarter hours, you will get one day instead of two.