DATETIME_DIFF() and Incorrect Timezone


#1

Hey there, Airtable Experts…

I have created a simple task table where I am attempting to use a formula field to automatically categorize individual tasks based on their due dates, i.e., Overdue, Due Today, Due Soon (2 days or less), etc. I have used the following formula:

IF(DATETIME_DIFF({Due Date}, NOW(), 'days') < 0, "1. Overdue", IF(DATETIME_DIFF({Due Date}, NOW(), 'days') = 0, "2. Today", IF(DATETIME_DIFF({Due Date}, NOW(), 'days') <= 2, "3. Due Soon (2 days or less)", IF(DATETIME_DIFF({Due Date}, NOW(), 'days') <= 7, "4. Upcoming (7 days or less)", IF(DATETIME_DIFF({Due Date}, NOW(), 'days') > 7, "5. Future", BLANK())))))

The challenge I’m having is that the calculated difference between the due date and the current date yields the incorrect category, i.e., items due today are showing as overdue, and items showing due tomorrow are showing as due today. This leads me to believe the timezone is incorrect.

I have tried swapping NOW() for TODAY(), but that only yields the same result.

Anyone have any idea what the issue may be and how to correct it?

Many thanks for your help!


#2

Try enabling the “Use same Timezone for all users” option only on the formula field (not on the date field).


#3

Thanks, @Jeremy_Oglesby, but I do not see that option in the Formula field anywhere, presumably because the output options for that field are not dates but text (e.g., “2. Today”).


#4

Doh…:roll_eyes: I didn’t think that one through


#5

But there is a date in the Formula, that field has the option checked on?


#6

There’s no option, and I believe that option is only available if the output from the formula is a date.


#7

This is kind of a round-about, hackey way to do this, but it may serve to verify what’s going on…

Try creating another formula field called “Today” with this formula:

DATETIME_FORMAT(
   TODAY(),
   'l'
)

And check to see that it returns the correct date.

Then try modifying it to:

DATETIME_FORMAT(
   SET_TIMEZONE(
      TODAY(),
      '<your timezone>'
   ),
   'l'
)

And see if it is still accurate. Try using that field as a go-between and reference it in your formula above and see if it changes anything.


#8

Yeah timezones in airtable are fairly tricky and often screw up my filters as well, I wish there were better options for controlling them. In situations like this where local times and UTC times are getting confused in formulas & filters, I’ve used some of W_Van_Hall’s advice in using SET_TIMEZONE to slide times around to match your local timezone in which you are trying to have your filters apply. Something like:


#9

I’m not talking about the Formula, but about {Due Date} field.


#10

Brilliant! This has fixed the issue. Thanks, @Jeremy_Oglesby!

Now the question becomes: why in the world is Airtable setting my timezone as UTC?


#12

Well, strictly speaking, it’s not: Since collaborators can be anywhere in the world, datetime calculations default to UTC.

Something to keep in mind — and it still screws me up regularly — is that selecting the ‘Use the same timezone (GMT) for all collaborators’ box does not merely specify a formatting option: It causes a modification to the underlying data. Selecting/deselecting the box does not simply toggle the presented value back and forth.