1

When I execute ll command I get the timestamps:

-rw-rw-r--+ 1    4167 May  5 17:19 file A    
-rw-rw-r--+ 1    2721 May  4 17:08 file B

I want the difference between timestamps of A and B

I tried this:

datetime.fromtimestamp(getmtime(file)).strftime('%h %m %s'))

It gives

May 05 1557032395
May 04 1557084082

Please help me get the time difference

jww
  • 97,681
  • 90
  • 411
  • 885
Ganga
  • 195
  • 1
  • 11
  • 4
    Possible duplicate of [How do I find the time difference between two datetime objects in python?](https://stackoverflow.com/q/1345827/608639), [Calculate time difference using Python](https://stackoverflow.com/q/23885390/608639), etc. – jww May 10 '19 at 18:17

1 Answers1

0

Looks like you need.

import os
import datetime

print(datetime.datetime.fromtimestamp(os.path.getmtime("file A")) - datetime.datetime.fromtimestamp(os.path.getmtime("file A")))

You can subtract 2 datetime objects to get the difference.

Rakesh
  • 81,458
  • 17
  • 76
  • 113