Get min and max dates

Cousin Stanley HooDunnit at didly42KahZidly.net
Thu Dec 8 14:49:03 EST 2016


DFS wrote:

> ....
> Not wanting to use any date parsing libraries,
> ....

  If you happen reconsider date parsing libraries 
  the  strptime  function  from the  datetime  module
  might be useful ....

#!/usr/bin/env python3

from datetime import datetime

dates = [ '10-Mar-1998' ,
          '20-Aug-1997' ,
          '06-Sep-2009' ,
          '23-Jan-2010' ,
          '12-Feb-2010' ,
          '05-Nov-2010' ,
          '03-Sep-2009' ,
          '07-Nov-2014' ,
          '08-Mar-2013' ]

dict_dates = { }

print( )

for this_date in dates :

    dt = datetime.strptime( this_date , '%d-%b-%Y' )

    sd = dt.strftime( '%Y-%m-%d' )

    print( '  {0} .... {1}'.format( this_date , sd ) )

    dict_dates[ sd ] = this_date


min_date = min( dict_dates.keys() )

max_date = max( dict_dates.keys() )

print( '\n  {0} .... {1}  min'.format( dict_dates[ min_date ] , min_date ) )

print( '\n  {0} .... {1}  max'.format( dict_dates[ max_date ] , max_date ) )








































-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona




More information about the Python-list mailing list