[Calculated date difference in time series processing]python

Source: Internet
Author: User
Tags date1

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.