Brian Dunning's FileMaker Custom Functions

CompareVersions ( versionA ; versionB )

Compares semantic version (semver) strings.

  Average rating: 5.0 (1 vote) Log in to vote

John Burwell   John Burwell - Show more from this author

Share on Facebook Share on Twitter

  Sample input:
CompareVersions ( "15.0.1" ; "16.0.3" )
  Sample output:
-1

  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.

Examples:
```
If [ CompareVersions ( Get ( ApplicationVersion ) ; "16.0.3" ) < 0 ]
# The client version is older than 16.0.3
Else
# The client is current or newer than 16.0.3
End If

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
End If
```

 

Comments

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: