CompareVersions ( versionA ; versionB )
Compares semantic version (semver) strings.
Average rating: 5.0 (1 vote) Log in to vote
John Burwell - Show more from this author
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
With semantic version (semver) strings (in the Major.Minor.Patch format, see https://semver.org), simple comparisons don't work, and the strings cannot be simply converted to numbers. Without comparing each segment individually, you cannot make reliable comparisons between semantic version strings.
This function splits two provided strings and compares each segment in turn. As soon as it finds one value greater than the other, it returns a signed integer indicating the result of the comparison.
The function returns -1 if A is less than B, 0 if A and B are equal, and 1 if A is greater than B.
If [ CompareVersions ( Get ( ApplicationVersion ) ; "16.0.3" ) < 0 ]
# The client version is older than 16.0.3
# The client is current or newer than 16.0.3
If [ CompareVersions ( "17.0.2" ; "16.0.3" ) < 0 ]
# False: 17.0.2 is a newer version than 16.0.3
Else If [ CompareVersions ( "17.0.2" ; "16.0.3" ) == 0 ]
# False: 17.0.2 is not the same as 16.0.3
Else If [ CompareVersions ( "17.0.2" ; "16.0.3" ) > 0 ]
# True: 17.0.2 is a newer version than 16.0.3
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.