Brian Dunning's FileMaker Custom Functions

time.Convert ( TmStamp ; localOffset ; FromForm ; toOffset ; ToForm )

Converts a timestamp from one format to another

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

Rob Poelking   Rob Poelking - Show more from this author
Kiza Solutions
https://kizasolutions.com

Share on Facebook Share on Twitter

  Sample input:
time.Convert ( "07/20/1969 4:33:26 PM" ; +5 ; +7 ; "FM" ; "sql" )
time.Convert ( "1969-07-20 18:33:26" ; +5 ; +7 ; "sql" ; "unix" )
time.Convert ( "-14174794" ; +5 ; +7 ; "unix" ; "xml" )
time.Convert ( "1969-07-21T16:33:26" ; 0 ; 0 ; "xml" ; "fm" )
time.Convert ( "12/17/2020 11:04:21 AM" ; "" ; "FM" ; 2 ; "ISO" )
  Sample output:
1967-06-23 16:33:26
-79687594
1967-06-23T16:33:26-00:00
6/23/1967 9:33:26 PM
2020-12-17T18:04:21+02:00

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

Converts the time stamp formats of FileMaker, XML (ISO 8601), SQL or Unix into another format by specifying the FromForm and ToForm. You can convert a time stamp in unix to xml or FileMaker to SQL.
UPDATED: now converts to specified time zone.

 

Comments

Chris McCue   Chris McCue, Dallas, TX
Sep 3, 2013
Great function! Moving records back and forth between FileMaker SOAP web services and MySQL tables is made much simpler with this handy calculation.
 
Christos Savva   Christos Savva, Cyprus
Jul 13, 2017
There is an issue with XML format for Eastern Hemisphere times.

This line:
sg = If ( sgn > 1 ; "+" ; "-");

Should be
sg = If ( sgn = 1 ; "+" ; "-");

Otherwise you never get +ve timezones.
 
Jason Wood   Jason Wood, Define Database
Mar 19, 2019
The example
time.Convert ( "1967-06-23T16:33:26-05:00"; "" ; "xml" ; "fm" )

Returns a "?" for me in FileMaker 17...
 
Rob Poelking   Rob Poelking, Kiza Solutions
Mar 20, 2019
Thank you, Jason. I had made a recent change to the function and I am using it in FM 17. I just input that same string and got back the correct form: 6/23/1967 9:33:26 PM. Note that (at least for xml) it is correctly evaluating the time offset of 5 hours.
 
Jason Wood   Jason Wood, Define Database
Mar 21, 2019
Hi Rob, I believe it's because of my Canadian localization, where dates are YYYY-MM-DD. I found another solution so no worries about fixing for me but I do think it's likely there is a dependency in here relating to the system format.
 
Jason Wood   Jason Wood, Define Database
Mar 21, 2019
Found it... if you are outside USA, you would have to update this line:
FMTSFormat = "mm/dd/yyyy hh:nn:ss" ;
 
caitlin   caitlin
Sep 24, 2020
Jason Woods - thanks for the heads up - I'm using this, and would have driven myself crazy if I didn't read your comment!
 
John Garbe   John Garbe
Dec 15, 2020
Thanks for sharing the great function. The offset doesn't work as I would expect, as these both generate the same result (12/15/2020 6:15 PM)
timestamp.Convert ( "2020-12-15T18:15:00.000Z" ; 0 ; "ISO" ; "FM" )
timestamp.Convert ( "2020-12-15T18:15:00.000Z" ; -6 ; "ISO" ; "FM" )
 
Rob Poelking   Rob Poelking, Kiza Solutions
Dec 17, 2020
Thank you, John, I've updated it to correct and have added the additional functionality to convert it completely from one timezone to the next.
 
Gustavo   Gustavo, Transcontinental Inc.
Oct 8, 2021
Hi Rob, I am just trying to create the Custom Function in my FM db, but I am getting an error, telling me that the localOffset parameter is not been found, I checked, I believe it is because is been declared as empty, Should I move something else to making it work ?
 
Gustavo   Gustavo, Transcontinental Inc.
Oct 8, 2021
I got it, I was needed to add all 5 parameters creating the Custom Functions, I am sorry about that..
 
Dan Shockley   Dan Shockley
Jan 10, 2023
First, thank you to Rob for putting together this useful function.

I found a (normally) minor issue: If the offset is 0 (local IS already UTC) and you are converting to ISO, the offset portion of the output is: "-00:00", which is a problem, since the ISO 8601 standard says that a zero-offset should be "+00:00". See https://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC
I've run into a case already where that non-standard negative symbol for zero-offset results in an error: calling MailChimp API with a query filtering by "since_last_changed", which takes an ISO 8601 timestamp. It was failing with an Internal Server Error until I changed to +00:00.

The code change that fixes this is in line 66, which should be:
>>> sgn = If ( Sign ( offset ) >= 0 ; "+" ; "-" );
…instead of:
>>> sgn = Choose ( Sign ( offset ) > 0 ; "-" ; "+" );
 
Rob Poelking   Rob Poelking, Kiza Solutions
Jan 11, 2023
Thank you Dan. Added that corrrection
 
Dan Shockley   Dan Shockley
Jan 30, 2023
Great!
Rob, can you clarify something for me? I'm getting a strange result, but perhaps I'm missing something.
If I use the function as follows:
time.Convert ( "2022-09-07T16:25:49+00:00" ; -5 ; "ISO" ; 0 ; "FM" ) /* 9/7/22, 4:25 PM, UTC */
…I expect to get back a FileMaker timestamp for that date at 11:25 AM. Instead, it seems to move _forward_ by 5 hours to 9:25 PM. I think the issue is that the offsetDelta variable is taking the Absolute value of the difference (and then the "fs" variable is set to that offsetDelta and used from then on to calculate the result). I don't think that ABS() function is correct.
What do you think? Is there something else it is accounting for?
 
Rob Poelking   Rob Poelking, Kiza Solutions
Jan 30, 2023
I think I had 2 errors there, Dan. I didn't need the ABS and I also have the wrong sign.
 

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 20 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: