You can download this code by clicking the button below.
This code is now available for download.
This function takes two date strings as input and calculates the difference in days between them.
Technology Stack : datetime
Code Type : Date calculation
Code Difficulty : Intermediate
import datetime
def time_difference(start_date, end_date):
"""
计算两个日期之间的时间差。
"""
start = datetime.datetime.strptime(start_date, "%Y-%m-%d")
end = datetime.datetime.strptime(end_date, "%Y-%m-%d")
delta = end - start
return delta.days