python - Type error comparing two datetimes -
my problem common you, didn't find answer on website. want combine 2 dates in python, use :
delta = 2012-04-07 18:54:40 - 2012-04-07 18:54:39
but error : typeerror: unsupported operand type(s) -: 'str' , 'str'
i understand it, don't know how turn right way.
do have idea?
thks!
you subtracting strings
, not datetime.datetime
objects. try strptime
method in order convert strings datetime.datetime
.
>>> delta = datetime.datetime.strptime('2012-04-07 18:54:40', '%y-%m-%d %h:%m:%s') \ - datetime.datetime.strptime('2012-04-07 18:54:39', '%y-%m-%d %h:%m:%s') >>> delta datetime.timedelta(0, 1)
Comments
Post a Comment