A tiny version.
import datetime
import random
def random_date(start, end):
"""Generate a random datetime between `start` and `end`"""
return start + datetime.timedelta(
# Get a random amount of seconds between `start` and `end`
seconds=random.randint(0, int((end - start).total_seconds())),
)
Note that both start
and end
arguments should be datetime
objects. If
you've got strings instead, it's fairly easy to convert. The other answers point
to some ways to do so.