Guest User

Untitled

a guest
Aug 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. from datetime import datetime, timedelta
  2. import mysql.connector
  3.  
  4. mydb = mysql.connector.connect(
  5. host="localhost",
  6. user="**USER**",
  7. passwd="**PASSWORT**",
  8. database="**DATABASE"**
  9. )
  10.  
  11. # Table already created like this:
  12. # mycursor.execute("CREATE TABLE events2 (id INT AUTO_INCREMENT PRIMARYKEY, name VARCHAR(255), startdate DATETIME, enddate DATETIME, deadline INT, position INT, reminder INT)")
  13.  
  14. name = "Testevent"
  15. startdate = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  16. enddate = datetime.now() + timedelta(days=14)
  17. deadline = 24
  18. position = 25
  19. reminder = 1
  20.  
  21. sql = "INSERT INTO events2 (name, startdate, enddate, deadline, position, reminder) VALUES (%s, %s, %s, %s, %s, %s)"
  22. val = (name, startdate, enddate, deadline, position, reminder)
  23. mycursor.execute(sql, val)
  24. mydb.commit()
  25.  
  26. mycursor = mydb.cursor()
  27.  
  28. mycursor.execute("SELECT startdate FROM events2 WHERE id = '7'")
  29.  
  30. myresult = mycursor.fetchone()
  31.  
  32. print(myresult)
  33. y = myresult + timedelta(days=14)
  34.  
  35. (datetime.datetime(2018, 8, 20, 18, 31, 42),)
  36. Traceback (most recent call last):
  37. File ".../Create_event.py", line 54, in <module>
  38. y = myresult + timedelta(days=14)
  39. TypeError: can only concatenate tuple (not "datetime.timedelta") to tuple
  40.  
  41. y = myresult[0] + timedelta(days=14)
Add Comment
Please, Sign In to add comment