Brian Dunning's FileMaker Custom Functions

UTCOffset

Returns the offset from UTC of the current device clock

  Average rating: 3.8 (47 votes) Log in to vote

Jeremy Bante   Jeremy Bante

https://github.com/jbante/

Share on Facebook Share on Twitter

  Sample input:
// Called from U.S. EST (New York) time zone

List (
UTCOffset;
Get ( CurrentTimestamp );
GetAsTimestamp ( Get ( UTCmSecs ) / 1000 + GetUTCOffset )
)
  Sample output:
-04:00:00
05-18-2012 17:04:31
05-18-2012 17:04:31.062

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Returns the offset from UTC of the current device clock. This can be used for establishing the time zone a device is operating in.

 

Comments

Jesse Barnum   Jesse Barnum, Atlanta, GA
Apr 3, 2014
Thanks, this was really handy.

One improvement: Using floor is better than using round, otherwise you'll be off by one second 50% of the time.
 
Jeremy   Jeremy, USA
Apr 3, 2014
Sounds reasonable enough. Done!
 
Matt Larson   Matt Larson, Cimbura.com
Oct 13, 2015
Not sure if I'm doing something wrong here… I'm getting results that are seemingly 1 hour off. I'm in Central Standard Time (CST).

Get(CurrentTimestamp) = 10/13/2015 9:00:00 PM
UTC Timestamp = 10/14/2015 3:00:00 AM
Difference = 6 hours

But, when I apply the UTCOffset CF to the UTC timestamp, it brings it back to 10 PM, which is only 5 hours difference. Is there a daylight savings issue going on or something?
 
Matt Larson   Matt Larson, Cimbura.com
Oct 16, 2015
Nevermind… I was looking at a map that told me to subtract 6 hours when apparently the correct UTC is 5 hours for me. Daylight savings issue or something. Your custom function is working correctly, and perfectly for me, now that I solved my root problem!
 
manda   manda, Slovenia
May 29, 2017
Anybody located East of UTC will not get the difference in seconds, but the Timestamp of that difference.

Change the formula to:
GetAsNumber ( Get ( CurrentTimestamp ) ) - Floor ( Get ( CurrentTimeUTCMilliseconds ) / 1000 )
 
Jeremy   Jeremy, Earth
May 30, 2017
The point of the function is not that it's result is a number or a timestamp, but that the result of adding and subtracting it with a timestamp results in a meaningful timestamp. I don't care if UTCOffset is a number or timestamp as long as Timestamp ( ... ) ± UTCOffset is a timestamp in typical use.
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.