Questions tagged [django-timezone]

Timezone handling specific questions with Django

Saving, displaying time is complicated when there are multiple timezones involved. In version 1.4 django web-framework has provided a way to handle them better.

This tag helps to consolidate questions related to use of Django timezone handling.

Here is detail documentation : Time zones

179 questions
69
votes
4 answers

django's timezone.now does not show the right time

My server is located in London. In my settings.py I have: TIME_ZONE = 'Europe/Moscow' USE_TZ = True But when I execute this: from django.utils import timezone print timezone.now().hour the code prints London's time. What am I doing…
imkost
  • 8,033
  • 7
  • 29
  • 47
30
votes
3 answers

Timezone.now() vs datetime.datetime.now()

When should I be using django's timezone.now() and when should I be using python's datetime.datetime.now(). For example, in the following INSERT which would make more sense? - Product.objects.create(title='Soap',…
David542
  • 104,438
  • 178
  • 489
  • 842
30
votes
3 answers

Django "default=timezone.now()" saves records using the "old" time of when the Django server starts

This issue has been occurring on and off for a few weeks now, and it's unlike any that has come up with my project. Two of the models that are used have a timestamp field, which is by default set to timezone.now(). This is the sequence that raises…
Lucas Ou-Yang
  • 5,505
  • 13
  • 43
  • 62
22
votes
1 answer

django DateTimeField with UTC offset?

I have a model with a DateTimeField: deadline = models.DateTimeField(verbose_name="Valid unitl", null=True, blank=True) Users should be allowed to input date, time and timezone info in the field. This is my desired format: 2012-12-31 23:30…
frnhr
  • 12,354
  • 9
  • 63
  • 90
18
votes
3 answers

DateTimeField received a naive datetime

I have model with DateTimeField column. I'm try to insert row with database current_time value directly into table by sql query. My sql query for MySQL database like: INSERT INTO MyTable (..., my_datetime, ...) VALUES (..., current_time, ...) And…
DoNotArrestMe
  • 1,285
  • 1
  • 9
  • 20
17
votes
7 answers

Django with system timezone setting vs user's individual timezones

How well does Django handle the case of different timezones for each user? Ideally I would like to run the server in the UTC timezone (eg, in settings.py set TIME_ZONE="UTC") so all datetimes were stored in the database as UTC. Stuff like this…
Nick Sonneveld
  • 3,356
  • 6
  • 39
  • 48
16
votes
3 answers

ValueError: Incorrect timezone setting while migrating manage.py file in Django

I am following the Django official documentation for writing my first app using Django. Here, it says that I have to set TIME_ZONE to my time zone in the settings.py file. The default value of TIME_ZONE was "utc" and i have changed it to…
ni8mr
  • 1,725
  • 3
  • 31
  • 58
15
votes
7 answers

How to automatically get user's timezone from client in Django?

I would like to know if there is a way to automatically retrieve user's timezone from client. Especially during login. I tried to add this in the login page (using auth.login): {% get_current_timezone as TIME_ZONE %} Then, add this in the login…
xpanta
  • 8,124
  • 15
  • 60
  • 104
12
votes
4 answers

Django DateTimeField says 'You are 5.5 hours ahead of server time.'

In one of my model I am storing time_stamp = models.DateTimeField(default=timezone.now) But when I save the model it says You are 5.5 hours ahead of server time. for example local time in my machine is 13:02 but after saving what gets stored in db…
Jayesh Singh
  • 696
  • 1
  • 9
  • 21
12
votes
3 answers

Django - How to run a function EVERYDAY?

I want to run this function everyday midnight to check expiry_date_notification. what can I do? I'm new to django and python. def check_expiry_date(request): products = Product.objects.all() for product in products: product_id =…
nabeel
  • 1,181
  • 2
  • 10
  • 24
9
votes
4 answers

How to get the current user's time zone in Django?

I'm trying to get my Django app work with the current user's time zone but I'm not getting any results... In my settings.py file I set: TIME_ZONE = 'UTC' And in my views.py, I set at the top of the code: activate(settings.TIME_ZONE) But this is…
Khris Vandal
  • 147
  • 1
  • 3
  • 14
8
votes
2 answers

Stop Django translating times to UTC

Timezones are driving me crazy. Every time I think I've got it figured out, somebody changes the clocks and I get a dozen errors. I think I've finally got to the point where I'm storing the right value. My times are timestamp with time zone and I'm…
Oli
  • 235,628
  • 64
  • 220
  • 299
8
votes
1 answer

Django datetimefield timezone aware CET

I saw this post Is Django corrupting timezone-aware DateTimeField when saving it to the Database? but it specifically uses pytz and mysql and what not where I don't use pytz and use SQLite (incase it might have an impact). I have the following…
ixje
  • 360
  • 1
  • 3
  • 20
8
votes
2 answers

How to use DateField in a Django form in a timezone-aware way?

I have a DateField in a Django 1.8 model, something like: from django.db import models birth_date = models.DateField() When it goes onto a form, I get back a 'naive' object: birth_date = the_form.cleaned_data['birth_date'] Printing birth_date in…
dfrankow
  • 20,191
  • 41
  • 152
  • 214
8
votes
1 answer

How to format DateTimeField in Django Admin to localtime?

How to format DateTimeField in Admin according to localtime and timezone ? My settings.py: TIME_ZONE = 'Europe/Bratislava' LANGUAGE_CODE = 'en-us' USE_I18N = True USE_L10N = True USE_TZ = True pytz package is installed.…
Edke
  • 161
  • 1
  • 1
  • 6
1
2 3
11 12