Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error - "SQLite DateTime type only accepts Python " "datetime and date objects as input."

I tried to declared a variable contains of Datetime like this

ts1.departure_date = '2012-03-03 10:10:10'

but then I got this error

StatementError: (exceptions.TypeError) SQLite DateTime type only accepts Python datetime and date objects as input. 

I wonder what is the correct way to declare a variable with datetime format? Thanks in advance

like image 656
wiko Avatar asked May 20 '15 08:05

wiko


1 Answers

First import the datetime class:

from datetime import datetime

Then create a datetime object and use that to set your attribute:

ts1.departure_date = datetime(2012, 3, 3, 10, 10, 10)
like image 52
Jon Clements Avatar answered Sep 29 '22 01:09

Jon Clements