Answer the question
In order to leave comments, you need to log in
Python. Getting the difference in minutes, how to do?
I take information like:
2019-03-31 17:04:39.645493from the database
delta1 = datetime.datetime.now() - lf1 # lf1 это 2019-03-31 17:04:39.645493
print(delta1.seconds())
Exception has occurred: TypeError
unsupported operand type(s) for -: 'datetime.datetime' and 'str'
Answer the question
In order to leave comments, you need to log in
I found a solution for white people
now = datetime.datetime.now()
now = str(now)
now = datetime.datetime.strptime(now[0:19],'%Y-%m-%d %H:%M:%S')
lf1 = datetime.datetime.strptime(lf1[0:19],'%Y-%m-%d %H:%M:%S')
minutes_diff1 = round((now - lf1).total_seconds() / 60.0)
Getting the date from your string
bd = '2019-03-31 17:04:39.645493'
dt = datetime.datetime.strptime(bd[0:19],'%Y-%m-%d %H:%M:% S')
And then you already have
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question