Moving the tday variable inside the function.

Thanks for the tip AnimalFarmPig