Brian Dunning's FileMaker Custom Functions

time.UTCtoLocal ( theTimeStamp ; ZoneOffset ; ObservesDST )

Converts UTC timestamp to local time DST adjusted

  Average rating: 4.3 (3 votes) Log in to vote

Rob Poelking   Rob Poelking - Show more from this author
Excelisys, Inc.
http://excelisys.com

Share on Facebook Share on Twitter

  Sample input:
time.UTCtoLocal ( GetAsTimestamp ( BE_UTCMilliseconds/1000 ) ; -5 ; 1 )
  Sample output:
7/13/2017 4:04:03.7 PM

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

Takes UTC (GMT) time stamp and converts it to local time assuming the correct time zone offset in hours +/-h and whether or not the local area observes Daylight Saving. The start and end dates for daylight saving may need to be adjusted for locale outside of the U.S.

Depends on function written by Koji Takeuchi, Splash, Inc. for the DateByNthDOW function.

 

Comments

Dan Fries   Dan Fries, Daniel Fries Music
Aug 20, 2019
Thank you for this work. I just put it into my solution with a slight modification, so that it returns the utc offset of a given date and time, I'm using it to send .ics files via email.

/**
* ==================================================================
* offset.DST ( theDate ; theTime; ZoneOffset ; ObservesDST )
*
* PARAMETERS:
* theDate Input Date
theTime Input time
* ZoneOffset (num) basic time zone offset in hours ignoring DST
* ObservesDST (bool) True, area observes DST. Leave false if the local area does not observe DST
* RETURNS:
* UTC offset of given date and time
*
* DEPENDENCIES:
* DateByNthDOW - Koji Takeuchi, Splash, Inc. https://www.briandunning.com/cf/1282
* PURPOSE:
* Use to convert UTC time stamps to local time
* NOTES:
* Adjust DST dates for your local zone. DST = Daylight Saving Time
* Thanks:
* 2017-07-13 Rob Poelking - Initial Release
* ==================================================================*
*/

Let ([

~offset = GetAsNumber (ZoneOffset) ;
~dateLocal = GetAsDate ( theDate ) ;
~timeLocal = GetAsTime ( theTime ) ;
~dstStart = DateByNthDOW ( Year(~dateLocal) ; 3 ; 1 ; 2 ) ; /* 2nd Sunday in March */
~dstEnd = DateByNthDOW ( Year(~dateLocal) ; 11 ; 1 ; 1 ) ; /* 1st Sunday in November */
~dst = GetAsBoolean ( ObservesDST ) ;
~isDS =
Case (
~dateLocal < ~dstStart ; False ;
~dateLocal > ~dstEnd ; False ;
~dateLocal = ~dstStart and ~timeLocal < Time ( 2;0;0) ; False ;
~dateLocal = ~dstEnd and ~timeLocal > Time (1;0;0) ; False ;
True
)
] ;

/* observes DST */
If (~isDS and ~dst ; ~offset + 1; ~offset)

)
 

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.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 15 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: