Skip to main content

How to compute the time difference between two data sets

In [ ]:
#If you have both date and time in year-month-dayThour:minute:second format, this function will compute the time difference in seconds:
import pyfits
import datetime

 def diff_time(t1, t2):

    h1, m1, s1 = t1.hour, t1.minute, t1.second
    h2, m2, s2 = t2.hour, t2.minute, t2.second
   t1_secs = s1 + (60*m1)
   t2_secs = s2 + (60*m2)
   return (t2_secs - t1_secs)

#More information about the datetime module:
#https://docs.python.org/2/library/datetime.html#