TODAY() Formula Returning Yesterday's Date

I’m running into an issue with a UI only field and the TODAY() function. For some reason, the TODAY() function is returning yesterday’s date. The full formula I’m using has a little more logic in it, but for debugging purposes I created another UI Only formula field with a date return type and a formula of “TODAY()”. As you can see in the example below today is 2/12/19 however the Today field in the model is showing 2/11/19.

I was thinking this might have something to do with timezones, but I’m not sure. I tried switching the formula to TODAY() + 1, but that didn’t return anything.

Something else that is pretty important to note. In testing, I found when I load the page and view the field value in the console it shows yesterday’s date. I can then refresh the page several times and still get yesterday as TODAY()'s value. Then for whatever reason, I’ll refresh the page again and it will show the correct date for TODAY(). At that point, I can keep refreshing the page and it will always show the correct date for TODAY().

I haven’t been able to find any consistent reason why this happens. Sometimes I have to refresh the page ~10 times to get the correct date and other times it takes many more refreshes. Regardless, once I close the page and preview it again in Skuid it always shows yesterday’s date for TODAY() until I refresh the page and it just happens to switch to today. This makes me think it’s not a timezone issue, but potentially a bug.

Thanks for posting Tim.

This is a known issue in Skuid and we are currently working on a way to resolve it without causing any issues for existing Pages.

The issue you’ve discovered is caused when the user’s Operating System (or “device”, as we call it) time zone is ahead of the time zone configured in Salesforce or Platform (we call it the “local” or “user” time zone). For example, if my laptop is configured to use Eastern Time (e.g. New York), but my Salesforce profile is setup to use Pacific Time (e.g. San Francisco), then the result of my formula, when converted to a DATE field type, will be yesterday’s date.

Ideally, we should be returning the date that it is in the user’s time zone when the function is called. So, continuing with the scenario above, if the device in New York says that it’s 1:00 AM on May 16th, we should be returning May 15th because it’s still 11:00 PM in San Francisco.

However, due to an oversight, rather than returning the date that it is right now in the user time zone, we’re returning the date that it was (get ready for it) in the user time zone at midnight in your device’s time zone. So, no matter when you call TODAY(), we ask “at midnight in New York, what date was it in San Francisco?”. This behavior was unintended and is not desirable.

Fortunately there’s a fairly easy work around. Rather than using TODAY(), we recommend using NOW(). If you convert NOW() to a date (via the Output Type property for your UI-Only Formula Field), then you’ll get the date that it is right now in the local (Salesforce configured) time zone, which is what TODAY() should be doing.

We’re putting our heads together on how to fix this issue without causing breaking changes for anyone that was, knowingly or not, depending on the current broken behavior. We’ll update this Post when we have a solution.

In the meantime, we recommend using NOW() instead of TODAY() for most scenarios.