Function Repository Resource:

# VersionOrder

Compare two version numbers to determine their order

Contributed by: Richard Hennigan (Wolfram Research)
 ResourceFunction["VersionOrder"][ver1,ver2] gives 1 if ver1 is before ver2 in version order, -1 if ver1 is after ver2 in version order and 0 if ver1 is the same version number as ver2.

## Details and Options

The values for veri can be given as numbers or strings.
A version specified as "1.10" is interpreted as the tenth point release of version 1, which is distinctly greater than "1.1".
A version string can have any number of periods.
Trailing zeros are disregarded, so long as the preceding values are equivalent, e.g. "1.2" is considered the same version as "1.2.0".
Leading zeros are not disregarded, e.g. "0.1.2" is considered a lower version than "1.2".

## Examples

### Basic Examples (4)

Compare version numbers:

 In[1]:=
 Out[1]=
 In[2]:=
 Out[2]=
 In[3]:=
 Out[3]=

Use numeric values:

 In[4]:=
 Out[4]=
 In[5]:=
 Out[5]=
 In[6]:=
 Out[6]=

Include letters:

 In[7]:=
 Out[7]=
 In[8]:=
 Out[8]=
 In[9]:=
 Out[9]=

Use the operator form:

 In[10]:=
 Out[10]=

### Scope (6)

Trailing zeros are ignored in the comparison:

 In[11]:=
 Out[11]=
 In[12]:=
 Out[12]=

Preceding zeros change the interpretation:

 In[13]:=
 Out[13]=
 In[14]:=
 Out[14]=

 In[15]:=
 Out[15]=
 In[16]:=
 Out[16]=

Versions are case-sensitive:

 In[17]:=
 Out[17]=

Versions can have any number of parts:

 In[18]:=
 Out[18]=
 In[19]:=
 Out[19]=

Numbers can be compared with strings:

 In[20]:=
 Out[20]=

### Applications (3)

Create a function that tests if a version is greater than a given value:

 In[21]:=
 In[22]:=
 Out[22]=
 In[23]:=
 Out[23]=
 In[24]:=
 Out[24]=
 In[25]:=
 Out[25]=
 In[26]:=
 Out[26]=

Filter a list of versions:

 In[27]:=
 Out[27]=

Use the resource function PythonPackageList to get a list of Python packages, and then sort the packages by their version number with VersionOrder:

 In[28]:=
 Out[28]=

Check paclet versions:

 In[29]:=
 In[30]:=
 Out[30]=
 In[31]:=
 Out[31]=
 In[32]:=
 Out[32]=

### Properties and Relations (3)

VersionOrder can be used as an ordering function in Sort:

 In[33]:=
 Out[33]=

Use VersionOrder with Ordering:

 In[34]:=
 Out[34]=
 In[35]:=
 Out[35]=

Compare with Sort:

 In[36]:=
 Out[36]=
 In[37]:=
 Out[37]=

VersionOrder works with OrderedQ:

 In[38]:=
 Out[38]=

Compare to standard ordering:

 In[39]:=
 Out[39]=

### Possible Issues (1)

Strings with unrelated numbers and letters can have unexpected results:

 In[40]:=
 Out[40]=
 In[41]:=
 Out[41]=
 In[42]:=
 Out[42]=

## Version History

• 1.0.0 – 29 August 2019