programming-examples/python/Math/Select a random date in the current year.py

7 lines
235 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
from datetime import date
import random
start_dt = date.today().replace(day=1, month=1).toordinal()
end_dt = date.today().toordinal()
random_day = date.fromordinal(random.randint(start_dt, end_dt))
print(random_day)