Skip to main content
5 of 5
Only marginally faster, not 2x faster as said in previous revision history
Aeronautix
  • 153
  • 1
  • 7

Using Python and dates file dates.txt:

from datetime import datetime
with open('dates.txt') as f:
    dts = [datetime.strptime(line.rstrip(), '%d-%b-%y') for line in f]
for k in sorted(dts):
    print(k.strftime('%d-%b-%y'))

Can also use dateutil.parser if you want to parse dates in different syntaxes:

from dateutil import parser
with open('dates.txt') as f:
    dts2 = [parser.parse(line) for line in f]
for k in sorted(dts2):
    print(k.strftime('%d-%b-%y'))

Both outputs the same, from oldest to newest:

12-Aug-21
01-Sep-21
24-Dec-21
02-Jan-22
11-Jul-22
Aeronautix
  • 153
  • 1
  • 7