Reference from: http://blog.csdn.net/sinat_37487842/article/details/72864462
1 Import Time2 Importdatetime3 4 #calculates two date difference days, a custom function name, and a variable name of two dates. 5 defCaltime (date1,date2):6 #%y-%m-%d is a date format in which the--can be substituted or not written, but unified, the same as the seconds after the same; you can only calculate dates, not time. 7 #Date1=time.strptime (date1, "%y-%m-%d%h:%m:%s")8 #Date2=time.strptime (Date2, "%y-%m-%d%h:%m:%s")9Date1=time.strptime (Date1,"%y-%m-%d") TenDate2=time.strptime (Date2,"%y-%m-%d") One #depending on whether you want to calculate the date or date time, you need to determine the number of array segments. Subscript 0 represents the year, the small Mark 1 represents the month, and so on ... A #Date1=datetime.datetime (date1[0],date1[1],date1[2],date1[3],date1[4],date1[5]) - #Date2=datetime.datetime (date2[0],date2[1],date2[2],date2[3],date2[4],date2[5]) -Date1=datetime.datetime (date1[0],date1[1],date1[2]) theDate2=datetime.datetime (date2[0],date2[1],date2[2]) - #returns the difference between the two variables, which is the difference in number of days - returnDate2-date1
[Calculated date difference in time series processing]python