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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -