title: Handling leap years in Python
body: <p>I have a program where the user enters a date and then compares it to another date to see which one comes first.</p>
  
  <p>How would I go about writing a code where the user inputs Feb 29 and the program returns Feb 28 instead (since there is no leap year)?</p>
  
  <p>Example:  </p>
  
  <pre><code>def date(prompt):
  ''' returns the date that user inputs and validates it'''  
  while True:
      try:
          date = raw_input(prompt)
          if len(date) &gt;= 5:
              month = date[0:2]
              day = date[3:5]
          dateObject = datetime.date(2011, int(month), int(day))
          return dateObject
      except ValueError:
              print "Please enter a valid month and day"
  </code></pre>