Please enable JavaScript to view this site.

ESL Documentation

Navigation: » No topics above this level «

Q2 How do I compare 2 dates to determine which is later?

Scroll Prev Top Next More

The following routine converts a date in DD/MM/YYYY format into a number so it can be compared with another date. The routine does not require the use of the DATE module nor the DATELIB library. There is no date validation, so it will attempt to convert invalid dates.

With minor modifications, this routine can be converted to accept dates in different formats including the American standard MM/DD/YYYY. Please contact the ESL Help Desk, if you need assistance with changing the input format.

CodeSamples_Q02_1

The routine makes no assumption regarding the century when using 2 digit years, but will work correctly if both dates use a 2 digit year and are from the same century. If the dates that are to be compared straddle the century (for example: 1997 and 2005), then you must convert the year into 4 digit form, using a "cut-off" year, which will be dependant on the type of dates being processed. The following fragment demonstrates the conversion of a 2 digit year to 4 digits based on a "cut-off" year of 1950.

CodeSamples_Q02_2

The "cut-off" year of 50 may appear valid for most uses, however, if the date is a retirement date in the future, then a year greater than 50 may be referring to this century.