A complete code for sorting dates.