Date objects don’t have a built-in compare() method, but comparing dates is still pretty easy.
The key is to not even look at the Date objects themselves, but rather the values represented by the objects using the Date.getTime() method:
Returns the number of milliseconds since midnight January 1, 1970, universal time, for a Date object. Use this method to represent a specific instant in time when comparing two or more Date objects.
This makes comparing dates as trivial as comparing numbers.
Here’s a simple method that compares two dates, returning -1 if the first date is before the second, 0 if the dates are equal, or 1 if the first date is after the second: