-1

I need to find the time interval in Python.

So far, I did:

from datetime import datetime
timestamp1 = 737029.3541666665
earliest_date = datetime.fromtimestamp(timestamp1)
timestamp2 = 737036.3527777778
most_recent_date = datetime.fromtimestamp(timestamp2)

But I don't know how to go further.

Thank you.

  • 1
    Please show us what you have tried. – Jan Christoph Terasa Mar 10 '20 at 18:09
  • 1
    Can you elaborate on what do you mean by "time interval of this dataset"? – DavidDr90 Mar 10 '20 at 18:15
  • @JanChristophTerasa I edited my question. –  Mar 10 '20 at 18:33
  • What is the issue, exactly? Have you tried anything, done any research? Stack Overflow is not a free code writing service. See: [tour], [ask], [help/on-topic], https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users. – AMC Mar 10 '20 at 19:59
  • 1
    @AMC My issue is solved, and what I have tried stays in my question! And Before I write something here I always search on the internet. When I cannot find a solution I ask it. So what's the problem? –  Mar 10 '20 at 20:21
  • Does this answer your question? [How do I find the time difference between two datetime objects in python?](https://stackoverflow.com/questions/1345827/how-do-i-find-the-time-difference-between-two-datetime-objects-in-python) – AMC Mar 10 '20 at 20:52
  • I saw you removed the picture, is your data in a Pandas DataFrame? – AMC Mar 10 '20 at 21:03
  • @AMC Yes it is. I used the following function "pd.read_csv()" to load the data set. –  Mar 10 '20 at 21:06
  • @Vera How are you finding the most recent and oldest date? – AMC Mar 10 '20 at 21:09
  • @AMC With the min() and max() functions. –  Mar 10 '20 at 21:10
  • `min(df["col_name"])` ? There's always `df["col_name"].min()`, too. – AMC Mar 10 '20 at 21:12
  • 2
    @AMC I used the second one `df["col_name"].min()` –  Mar 10 '20 at 21:13

1 Answers1

0

If you have two timestamps like (based in your example):

from datetime import datetime
timestamp1 = 737029.3541666665
timestamp2 = 737036.3527777778
earliest_date = datetime.fromtimestamp(timestamp1)
most_recent_date = datetime.fromtimestamp(timestamp2)

The most simple way to get the time interval between these two date is like:

interval = most_recent_date - earliest_date
# this is a datetime.timedelta object but you can use str() and get some human readable string
str(interval)
# returns: '0:00:06.998611'
soloidx
  • 729
  • 6
  • 12
  • An additional question. The output 0:00:06.998611 is this a constant time interval? Or not? –  Mar 10 '20 at 22:24
  • 2
    yes, it's the time difference between these two dates so, it should be constant if the dates are the same. – soloidx Mar 11 '20 at 03:34