I am using python, and want to calculate the difference between two times.
Actually i had scenario to calculate the difference between login and logout times,
for example in organizations there is some particular limit for working hours, so
if a user login at 9:00 AM
in the morning and if he logs out at 6:00 PM
in the evening,
we need to calculate how much duration he stayed in the office(which is 9 hours
in the present scenario ), but i want to do this in python, so can anyone please let me know how to achieve the above concept of calculating the difference between login and logout times ?
>>> start = datetime.datetime(year=2012, month=2, day=25, hour=9)
>>> end = datetime.datetime(year=2012, month=2, day=25, hour=18)
>>> diff = end - start
>>> diff
datetime.timedelta(0, 32400)
>>> diff.total_seconds()
32400
>>> diff.total_seconds() / 60 / 60
9
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With