# Python. Getting the difference in minutes,how to do?

I take the information like:
2019-03-31 17:04:39.645493
from dB
Next, I need to know how many minutes passed since that moment and now that's what I built:
``````delta1 = datetime.datetime.now() - lf1 # lf1 is 2019-03-31 17:04:39.645493
print(delta1.seconds())``````

I got
Exception has occurred: TypeError
unsupported operand type(s) for -: 'datetime.datetime' and 'str'

I know, not subtract from daytime line, but then voosche count? What supposedly this deyt time?
March 19th 20 at 09:25
March 19th 20 at 09:27
Solution
Found here for white people the decision
``````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)``````

Displays rounded to the difference in minutes
March 19th 20 at 09:29
Get a 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 have
``````ref = datetime.datetime.strptime(lf1[0:19],'%Y-%m-%d %H:%M:%S')
ref = ref datetime.datetime.now()

print(ref)``````

Issues

-1 day, 23:54:20.069267

How to get minutes? - dudley commented on March 19th 20 at 09:32
Well it is possible so

print(ref.seconds/60)

And so, read the documentation for the module.
Use the Directive dir() - ada.Lueilwitz50 commented on March 19th 20 at 09:35
@dudley, it is probably better to subtract the past from the present. From the resulting timedelta object has a method `seconds`that returns the number of seconds, the seconds divide by 60. - Kayli.Cart commented on March 19th 20 at 09:38

Find more questions by tags Work with date / timePython