title: Checking if date is valid with two different format
body: <p>So I've created the following function, the idea is to check whether the data is either in YYYY-MM-DD or MM/DD/YYYY formats and return a corresponding value. If not return -1.</p>
  
  <pre><code>from datetime import datetime
  
  def dateValidate(date):
  
      try:
          if date != datetime.strptime(date, "%Y-%m-%d").strftime("%Y-%m-%d"):
                  raise ValueError
          return 1
          if date == datetime.strptime(date, "%m/%d/%Y").strftime("%m/%d/%Y"):
                  raise ValueError
          return 2
      except ValueError:
          return -1
  </code></pre>
  
  <p>However it doesn't seem to work  for the MM/DD/YY format. Any ideas on what's going wrong?</p>
  
  <p>Edit:</p>
  
  <pre><code>import datetime
  
  def validate(date):
      try:
          if date != datetime.datetime.strptime(date, "%Y-%m-%d").strftime("%Y-%m-%d"):
              raise ValueError
          return 1
      except ValueError:
          return -1
      try:
          if date == datetime.datetime.strptime(date, "%m/%d/%Y").strftime("%m/%d/%Y"):
              raise ValueError
          return 2
      except ValueError:
          return -1
  </code></pre>
  
  <p>This returns <code>-1</code> for <code>validate('07/15/1996')</code>.</p>