Created
September 8, 2015 06:04
-
-
Save fcojperez/354849b9002bf57dbd8b to your computer and use it in GitHub Desktop.
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
# Snippet para calcular fechas aleatorias en un periodo definido por los parametros StartDate y EndDate | |
# 07/09/2015 | |
# Francisco Pérez, [email protected] | |
import datetime | |
import random | |
#Comienzo del periodo el 01/01/2015 a las 0:00 | |
sDate = datetime.datetime(2014,1,1,0,0) | |
#Fin del periodo el 31/12/2015 a las 23:59 | |
eDate = datetime.datetime(2015,12,31,23,59) | |
def random_date(StartDate,EndDate): | |
dif = EndDate - StartDate | |
rnd = dif * random.random() | |
return StartDate + rnd | |
#Prueba de la función random_date() | |
test = random_date(sDate, eDate) | |
#print test.strftime("%d/%m/%y %H:%M:%s") | |
print(test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment