I want to save the datetime in the database as midnight for a specific user. I save the timezone on my user object. However, the database keeps saving it as midnight in UTC. Below is the code I am using.
tz_obj = pytz.timezone(user.timezone) start_date = tz_obj.normalize(date_obj.replace(day=1, hour=0, minute=0, second=0, microsecond=0)) end_date = tz_obj.normalize(date_obj.replace(day=calendar.monthrange(date_obj.year, date_obj.month)[1], hour=23, minute=59, second=59, microsecond=99999)) obj = MyObject.objects.create(start=start_date, end=end_date) Can someone show me how to make sure that the UTC date saved in the database is equivalent to midnight in the specified timezone.
Update Each user could have a different timezone so setting the timezone in the settings file does not solve this problem.