-2

How to get the difference between two timestamps in days?

  "min": 1487344607000,
  "max": 1492442207000,
user7379562
  • 349
  • 2
  • 6
  • 15
  • 1
    Possible duplicate of [python - Difference between two unix timestamps](https://stackoverflow.com/questions/45603232/python-difference-between-two-unix-timestamps) –  Oct 13 '17 at 12:30

2 Answers2

4

Here is a quick example,

import datetime

min = min/1000           #removing milli seconds
max = max/1000

min = datetime.datetime.fromtimestamp(min)
max = datetime.datetime.fromtimestamp(max)

print("Total Days : " + str((max-min).days))
Stack
  • 4,116
  • 3
  • 18
  • 23
2

There are 2 interpretations:

import datetime
date1=datetime.datetime.fromtimestamp(min/1000)
date2=datetime.datetime.fromtimestamp(max/1000)
delta = date2-date1
days = delta.days

Or if the difference must be a full day:

days=(max-min)/86400
farbiondriven
  • 2,450
  • 2
  • 15
  • 31