You can download this code by clicking the button below.
This code is now available for download.
This function generates a random date between two specified dates.
Technology Stack : datetime, random
Code Type : Function
Code Difficulty : Intermediate
import datetime
import random
def random_date(start, end):
"""
Generate a random datetime between two dates.
"""
delta = end - start
random_seconds = random.randrange(delta.total_seconds())
return start + datetime.timedelta(seconds=random_seconds)