# DATE (comparison functions)

The DATE function is used to compare two dates.

- Number of roles
- 1
- Number of dimensions

(in each role) - 1
- Weight table
- mpi_wgtnval, mpi_wgthead, mpi_wgt1dim

- If the lengths of the two strings are eight characters, then the year is extracted from both strings and the years are compared. If the years are equal, then the month and day are extracted and compared. If they are all equal, then the weight is computed by adding the weight for index1 from mpi_wgt1dim to the weight for this particular year from mpi_wgtnval table. If the strings are less than or greater than eight characters, they are treated as ANON.
- If the dates match exactly, or the edit-distance is zero, then the weight is a combination of two tables—mpi_wgtnval and mpi_wgt1dim table.
- If they do not match exactly, the corresponding edit-distance value is used as a lookup in the mpi_wgt1dim table. Here the mpi_wgtnval table is not used. If the dates of one string match with the month of the other string and vice versa, it is a transposed match and the distance is treated as one.

DATE example:

1978-24-03 and 1978-24-03 have an exact match. Therefore, the weight will be the weight for index 1 in mpi_wgt1dim + weight for 1978 in the mpi_wgtnval table.

1978-24-03 and 1978-03-24 will have a single transposition and an edit distance of 1. Thus, the weight will be the weight for index 2 in the mpi_wgt1dim table.

1978-24-03 and 1979-24-03 have an edit-distance of 1 and the weight is the weight that corresponds to index 2 in mpi_wgt1dim.

## Weight tables

The following are examples of the weight tables expected.

- mpi_wgthead
`1|1|A|CMPID-DOB-DIST|1DIM|CMPID-DOB-DIST|5|0|0|0| 1|1|A|CMPID-DOB-YEAR|NVAL|CMPID-DOB-YEAR|0|0|0|0|`

- mpi_wgtnval
`1|1|A|CMPID-DOB-YEAR|-1|394|`

- mpi_wgt1dim
`1|1|A|CMPID-DOB-DIST|0|0| 1|1|A|CMPID-DOB-DIST|1|0| 1|1|A|CMPID-DOB-DIST|2|182| 1|1|A|CMPID-DOB-DIST|3|18| 1|1|A|CMPID-DOB-DIST|4|-190|`