You can download this code by clicking the button below.
This code is now available for download.
The function generates a random date between two specified dates.
Technology Stack : The package and technology stack used by the code
Code Type : Function
Code Difficulty : Intermediate
import datetime
import random
def generate_random_date(start_date, end_date):
"""
Generate a random date between two given dates.
"""
start = datetime.datetime.strptime(start_date, "%Y-%m-%d")
end = datetime.datetime.strptime(end_date, "%Y-%m-%d")
delta = end - start
random_seconds = random.randrange(delta.total_seconds())
return start + datetime.timedelta(seconds=random_seconds)