Here are the relevant settings in my project:
settings.py
TIME_ZONE = "US/Mountain"
USE_TZ = True
models.py (using timezone.now)
class Submission(models.Model):
date_created = models.DateField(
default=timezone.now,
blank=True,
)
datetime_created = models.DateTimeField(
default=timezone.now,
)
If I create a Submission at 5PM MST on 03/01/2023 these are the values I get:
date_created: "2023-03-02"datetime_created: "2023-03-01 17:00:00-07:00"
Why would date_created be using the date of the following date?
I think the reason this happens is because the "date" (without the time) isn't timezone aware.
You can see in the DateField source where Django automatically converts a datetime back to UTC:
Personally I would use a
DateTimeFieldso you keep the timezone information, and just access.datewhen you need it, but you should be able to usedatetime.date.today(assuming you don't want to use theauto_now_addoption for some reason):