title: python - Insert DateTime field in Ms-Sql
body: <p>I want to insert a date into Ms-SQL DB. How can I do that?</p>
  
  <p>Here's what I'm doing:-</p>
  
  <pre><code>a = (datetime.datetime.now()).strftime("%Y-%m-%d %H:%M:%S")
  data =  {'AWB_Number':'1','Weight':'1','Length':'1','Height':'1','Width':'1','Customer_Name':'Naaptol','Scan_Time': a,'Series_Flag':'Others'}
  
  data = (
          data['AWB_Number'], data['Weight'], data['Length'], data['Height'],
          data['Width'], data['Customer_Name'], data['Scan_Time'] ,data['Series_Flag']
          )
  
  print data
  
  
  con_string = 'DSN=%s;UID=%s;PWD=%s;DATABASE=%s;' % (aramex_dsn, aramex_user, aramex_password, aramex_database)
  cnxn = pyodbc.connect(con_string)
  
  cursor = cnxn.cursor()
  
  cursor.execute("insert into data_AutoScale_DELHUB VALUES (%s, %s, %s, %s, %s, %s, %s, %s)" % data)
  cnxn.commit()
  
  cnxn.close()
  </code></pre>
  
  <p>It returns an error saying</p>
  
  <pre><code>Traceback (most recent call last):
    File "tests.py", line 39, in &lt;module&gt;
      cursor.execute("insert into data_AutoScale_DELHUB VALUES (%s, %s, %s, %s, %s, %s, %s, %s)" % data)
  pyodbc.ProgrammingError: ('42000', "[42000] [FreeTDS][SQL Server]Incorrect syntax near '09'. (102) (SQLExecDirectW)")
  </code></pre>
  
  <p>What is the problem?</p>
  
  <p>Following is the Database structure:-</p>
  
  <pre><code>    AWB_Number = models.CharField(max_length = 255)
      Weight = models.CharField(max_length = 255)
      Length = models.CharField(max_length = 255)
      Width = models.CharField(max_length = 255)
      Height = models.CharField(max_length = 255)
      Customer_Name = models.CharField(max_length = 255)
      Scan_Time = models.DateTimeField(db_index = True)
      Series_Flag = models.CharField(max_length = 255)
  </code></pre>