It’s fairly easy to extract the Date portion of a Datetime value in a Flow formula.
DATEVALUE({!datetimeValue})
If {!datetimeValue} = 7/22/2020 5:00 PM then the formula will return July 22, 2020.
It is a bit trickier to convert a Date value to a Datetime value using a formula.
DATETIMEVALUE(TEXT({!dateValue}) + ” 00:00:00″)
If {!dateValue} = July 22, 2020 you would want the formula to return 7/22/2020 12:00 AM. Instead the value returned will be converted to GMT so the result I get in Portland, Maine is 7/21/2020 8:00 PM. For me, that’s 4 hours ahead of GMT.
I could find no easy way to do time-zone calculations in Flow so I created a Flow Action that would keep everything in my current time-zone.
With this action, my result for July 22, 2020 is 7/22/2020 12:00 AM.
If you want a timestamp of other than 12:00 AM, you can pass in the desired hour, minute and second values.
Attributes
Attribute | Type | Notes |
Date Value | Date | The Date to be used for the Datetime value |
Hour Value (Default = 0) | Integer | (Optional) The Hour value to be used for the Datetime value (0-23) |
Minute Value (Default = 0) | Integer | (Optional) The Minute value to be used for the Datetime value (0-59) |
Second Value (Default = 0) | Integer | (Optional) The Second value to be used for the Datetime value (0-59) |
Use Case
Read about an example that uses this action in a Flow to get the Time Zone offset for the running User.
Install
Created by – Eric Smith – July 2020
Unmanaged v1.0 (Production/Developer)
Unmanaged v1.0 (Sandbox)
Thanks a lot for this Eric. Is this based on the running user’s timezone or the org’s?
LikeLike
I think it is dependent on the running user. If you end up testing the various combinations, please let me knwo what your results are.
LikeLike
Yes, I will. In fact, I am wondering if I can use this for time zone conversions. I could not solve this when working on a requirement before.
LikeLike
Hello Eric, I finally found the need and the time to use this. This is awesome. I think you should potentially write a new blog post or update this one to show folks that this can be used to find the GMT offset of the timezone the user currently is in. I don’t think this is possible any other way in Salesforce Flow. In summary, I used your action to find the day start time in the user’s timezone and I know flow gives me the day start time in GMT. When I take the difference, I find the correct offset hours I need to use to convert GMT system times by before I display them to the user. Awesome. Here is the result for ET:
Current Time: 2/16/2022, 6:17 PM
Day Start: 2/15/2022, 7:00 PM
User Timezone Day Start: 2/16/2022, 12:00 AM
GMT offset: 5
Cheers.
LikeLiked by 1 person
Here’s the new post.
LikeLike
That’s an awesome use case Andy!
LikeLike
Question, to get the hours and mins
7/22/2020 5:05 PM – 7/22/2020 4:00 PM = hours and mins?
LikeLike
If you subtract two datetime values you will get the number of days with the fractional amount giving you the hours/minutes. For example 1.5 equals 1 day, 12 hours, 0 minutes.
LikeLike