greater than 'date' python 3
Question: I would like to be able to do greater than and less than against dates. How
would I go about doing that? For example:

    
    
    date1 = "20/06/2013"
    date2 = "25/06/2013"
    date3 = "01/07/2013"
    date4 = "07/07/2013"
    
    
    datelist = [date1, date2, date3]
    
    for j in datelist:
         if j <= date4:
              print j
    

If I run the above, I get date3 back and not date1 or date2. I think I need I
need to get the system to realise it's a date and I don't know how to do that.
Can someone lend a hand?

Thanks


Answer: You can use the [`datetime`](http://docs.python.org/2/library/datetime.html)
module to convert them all to datetime objects. You are comparing strings in
your example:

    
    
    >>> from datetime import datetime
    >>> date1 = datetime.strptime(date1, "%d/%m/%Y")
    >>> date2 = datetime.strptime(date2, "%d/%m/%Y")
    >>> date3 = datetime.strptime(date3, "%d/%m/%Y")
    >>> date4 = datetime.strptime(date4, "%d/%m/%Y")
    >>> datelist = [date1, date2, date3]
    >>> for j in datelist:
    ...      if j <= date4:
    ...           print(j.strftime('%d/%m/%Y'))
    ... 
    20/06/2013
    25/06/2013
    01/07/2013
    

