title: Django Validate Date & Time in Forms
body: <p>I have a view where I validate date and time on form submit making sure the date + time are not past. Date and Time are two separate fields. It works, but I know its wrong way of doing it and the date+time should be validated in Django Forms. </p>
  
  <p>This is in my <code>view.py</code></p>
  
  <p>(Probably not done the right way but it works)</p>
  
  <pre><code>my_date = request.session['reservationdate'] #in "mm/dd/yyyy" format
  my_time = request.session['reservationtime'] #in "hh:mm" format
  my_date_time = (my_date + ' ' + my_time + ':00') #convert to "mm/dd/yyyy hh:mm:ss"
  my_date_time = datetime.strptime(my_date_time, '%m/%d/%Y %H:%M:%S') #convert to valid datetime
  if datetime.now() &lt;= my_date_time:
      #do this
  else:
       ...
  </code></pre>
  
  <p>now my goal is to have something like the above in Django forms:</p>
  
  <pre><code>class MyForm(forms.ModelForm):  
  
      def __init__(self, *args, **kwargs):
          super(MyForm, self).__init__(*args, **kwargs)
  
          self.fields['my_date'].required = True
          self.fields['my_time'].required = True
          ...
  
      def clean_my_date(self):
          my_date = self.cleaned_data['my_date']
          my_time = self.cleaned_data['my_time']
          my_date_time = (my_date + ' ' + my_time + ':00')
          my_date_time = datetime.strptime(my_date_time, '%m/%d/%Y %H:%M:%S')
          if datetime.now() &lt;= my_date_time:
              raise forms.ValidationError(u'Wrong Date!')
          return my_date
  
      class Meta:
          model = MyModel
          fields = ['my_date', 'my_time', ...]
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p><strong>working code:</strong></p>
  
  <pre><code>def clean_my_time(self):
     my_date = self.cleaned_data['my_date']
     my_time = self.cleaned_data['my_time']
     my_date_time = ('%s %s' % (my_date, my_time))
     my_date_time = datetime.strptime(my_date_time, '%Y-%m-%d %H:%M:%S')
     if datetime.now() &gt;= my_date_time:
          raise forms.ValidationError(u'Wrong Date or Time! "%s"' % my_date_time)
     return my_time
  </code></pre>
  
  <p>Thanks to all for the help especially <strong>xyres</strong> for his work and for being patient with me!</p>