Apex Aide apexaide

Use Flow to get the running User’s Time Zone offset from GMT

By Eric Smith· ericsplayground.wordpress.com· ·Intermediate ·Admin ·4 min read
Summary

This explains how to accurately calculate a user's time zone offset from GMT within Salesforce Flows, a capability not natively supported by formulas. By leveraging a custom Flow Action that converts Dates to DateTime at midnight GMT, and comparing it to the user’s local time, the exact offset including Daylight Savings adjustments can be determined dynamically. This method solves complex issues with time zone and daylight savings handling in declarative automation, enabling accurate date/time display and calculations in Flows. Salesforce teams can implement this sub-flow to improve user-specific DateTime processing without complex formulas or Apex.

Takeaways
  • Use a Convert Date to Datetime Flow Action to get midnight GMT datetime.
  • Calculate user GMT offset by comparing converted DateTime to DATETIMEVALUE(Date).
  • Create a sub-flow with input Date and output Number for reusable GMT offset.
  • Account for Daylight Savings Time changes in time zone offset calculations.
  • Leverage this pattern to accurately display and process datetime values per user.

A couple of years ago, I created a component to convert a Date value to a Datetime value in a Flow. Recently, Andy Engin Utkan, figured out a way to use this component to overcome issues he was having when using a Display Text component in a Flow when trying to show Datetime values and have them display in the correct time zone. You are unable to use a formula in Salesforce to determine a User’s time zone. Admins have created very complex formulas trying to calculate an offset based on the User’s State or Country but then they ran into issues trying to handle Daylight Savings Time adjustments as well. Here’s an example presented by Eric Praud on Jen Lee’s “ How I Solved This ” Admin Podcast where he created a new custom object, added 9 custom fields to the User object and came up with this formula to get the hour of the day when converted to the User’s local time: IF( OR( ISBLANK( $User.

Flow BuilderUncategorized