Last active
December 14, 2015 01:59
-
-
Save daleobrien/5010722 to your computer and use it in GitHub Desktop.
random date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randrange | |
from datetime import timedelta, datetime | |
def random_date(start, end): | |
""" | |
This function will return a random datetime between two datetime | |
objects. | |
""" | |
delta = end - start | |
int_delta = (delta.days * 24 * 60 * 60) + delta.seconds | |
random_second = randrange(int_delta) | |
return (start + timedelta(seconds=random_second)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment