How to generate random date in iso format in a particular month with unique values.
This code will get the date in iso format, But how to generate random date in iso format in a particular month with unique values for all the dates in that month
from datetime import datetime, timedelta
import random
def random_date(d1, d2):
delta = d2 - d1
seconds = delta.total_seconds()
n = random.randrange(seconds)
return d1 + timedelta(seconds=n)
d1 = datetime.strptime('1/1/2019 1:30 PM', '%m/%d/%Y %I:%M %p')
d2 = datetime.strptime('1/2/2019 4:50 AM', '%m/%d/%Y %I:%M %p')
print(random_date(d1, d2).isoformat(timespec='milliseconds')+'Z')
Aucun commentaire:
Enregistrer un commentaire