title: Parsing dates using WTForms Flask - Python
body: <p>Hi So I've been using WTForms with success for a good period of time now.</p>
  
  <p>The problem is on how to parse dates.</p>
  
  <p>I've always used to assign variables according to form data as follows</p>
  
  <pre><code>firstname = form.firstname.data
  </code></pre>
  
  <p>This will store the user's input from the form data into my variable called "firstname", which works just fine, my problem is when it comes to dates.</p>
  
  <p>I have the following code</p>
  
  <p><strong>WTForms Class</strong></p>
  
  <pre><code>class BookingForm(Form):
  start_date = DateField('Start Date', format='%m/%d/%Y')
  end_date = DateField('End Date', format='%m/%d/%Y')
  </code></pre>
  
  <p><strong>The booking route</strong></p>
  
  <pre><code>@app.route('/book/', methods=['GET','POST'])
  @login_required
  def book():
  try:
      form = BookingForm(request.form)
  
      if request.method == "POST" and form.validate():
          start_date = form.start_date.data
          end_date = form.end_date.data
          # I Have also tried form.start_date.data.strftime('%m-%d-%Y') with no luck
   ...
  </code></pre>
  
  <p><strong>The HTML Template {jinja}</strong></p>
  
  <pre><code>&lt;div class="col-md-4"&gt;
       {{ render_date_field(form.start_date) }}
  &lt;/div&gt;
  &lt;div class="col-md-4"&gt;
       {{ render_date_field(form.end_date) }}
  &lt;/div&gt;
  </code></pre>
  
  <p>I am also using datetime in python</p>
  
  <pre><code>from datetime import datetime
  </code></pre>
  
  <p>I've been trying to follow many docs on how to parse a date into a variable from a user input form with no luck, Does anybody know the right syntax?</p>
  
  <p>Thanks</p>