You can download this code by clicking the button below.
This code is now available for download.
This function takes two dates as input and calculates and returns a random time interval between the two dates.
Technology Stack : Pendulum
Code Type : Function
Code Difficulty : Intermediate
import random
from pendulum import DateTime, Interval
def random_date_difference(start_date, end_date):
"""
Calculate a random date difference between two dates.
"""
start = DateTime(start_date)
end = DateTime(end_date)
interval = Interval(random.randint(0, 365*24*60*60))
random_date = start.add(interval)
return random_date