Q:

Generate Random Date/Time Python 2.6

I want to create a function that will create a random timestamp and cast into a string. Tried a couple ways but not sure if the problem is using python 2.6
Tried this but running into error that says:
TypeError: unsupported operand type(s) for *: 'datetime.timedelta' and 'float'

def gen_datetime(min_year=2018, max_year=datetime.now().year):

    start = datetime(min_year, 1, 1, 00, 00, 00)

    years = max_year - min_year + 1

    end = start + timedelta(days=365 * years)

    return start + (end - start) * random.random()

...
randomTime = str(gen_datetime())

A:

The multiplication of a datetime.timedelta object with a float was only introduced int Python 3.x. You can confirm this comparing the Datetime docs from Python 2.x and the Datetime docs from Python 3.x
Notice that Python 2.x accepts int and long so it should be fine multiplying it by:
random.randint(a,b)

which will generate an int between a and b

