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

Using Python and dates file dates.txt:

from datetime import datetime
with open('dates.txt') as f:
    dts = [datetime.datetime.strptime(line.rstrip(), '%d-%b-%y') for line in f]
dts.sort()
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]
dts2.sort()
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

Using Python and dates file dates.txt:

import datetime
with open('dates.txt') as f:
    dts = [datetime.datetime.strptime(line.rstrip(), '%d-%b-%y') for line in f]
dts.sort()
for k in 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]
dts2.sort()
for k in 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

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
Rollback to Revision 2
Source Link
Aeronautix
  • 153
  • 1
  • 7

Using Python and dates file dates.txt:

from datetime import datetime
with open('dates.txt') as f:
    dts = [datetime.datetime.strptime(line.rstrip(), '%d-%b-%y') for line in f]
dts.sort()
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]
dts2.sort()
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

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

Using Python and dates file dates.txt:

import datetime
with open('dates.txt') as f:
    dts = [datetime.datetime.strptime(line.rstrip(), '%d-%b-%y') for line in f]
dts.sort()
for k in 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]
dts2.sort()
for k in 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
Minor 2x speed improvement
Source Link
Aeronautix
  • 153
  • 1
  • 7

Using Python and dates file dates.txt:

from datetime import datetime
with open('dates.txt') as f:
    dts = [datetime.datetime.strptime(line.rstrip(), '%d-%b-%y') for line in f]
dts.sort()
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]
dts2.sort()
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

Using Python and dates file dates.txt:

import datetime
with open('dates.txt') as f:
    dts = [datetime.datetime.strptime(line.rstrip(), '%d-%b-%y') for line in f]
dts.sort()
for k in 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]
dts2.sort()
for k in 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

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
Add dateutil.parser
Source Link
Aeronautix
  • 153
  • 1
  • 7
Loading
Source Link
Aeronautix
  • 153
  • 1
  • 7
Loading