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
0
votes
1 answer

django time display by using timesince

I am using the Django template filter tag timesince. it displays well time Greater than one minute. But when is less than one minute it showing 0 minutes ago i want it to be in seconds here is my code

{{ article.article_published_date| timesince…

0
votes
2 answers

Django using the wrong Timezone for the data imported from MySQL

I use Django 3 + Bootstrap 4 + MySQL 5.7 on a Laragon server, all on Windows 10. My setting in Django : TIME_ZONE = 'Europe/Paris' My setting in MySQL : TIME_ZONE = SYSTEM (My system is configured with 'Europe/Paris') When I use a timezone.now() in…
Frederic
  • 115
  • 10
0
votes
1 answer

How to convert a datetime from a specific timezone to its UTC version using the django.utils.timezone library?

I am looking for a function from the django.utils.library that would take a datetime from a specified timezone and return its UTC equivalent. Does such a function exist?
Extranomical
  • 385
  • 1
  • 3
  • 13
0
votes
1 answer

problem with timezone and datetime libs in Django 2 and python 3

I'm a bit confused by the daylight savings handling. I have working on web notifier application in Django 2.0.6 framework and python 3.6. this application provide scheduling notification. for example users schedule message for some hours later or a…
Erfan
  • 485
  • 2
  • 6
  • 13
0
votes
1 answer

How to query in django datetimefield with default timezone.now for a specific day?

I have a model Game with datetimefield set to default timezone.now(). class Game(models.Model): time = models.DateTimeField(default=timezone.now, blank=True, null=True) I want to query how many games were played on a specific day. I have tried…
Savitoj Cheema
  • 460
  • 2
  • 9
  • 22
0
votes
0 answers

Django timezone struggles

I am having difficulty getting queryset results in my own timezone. for example: model field definition: some_datetime_field= models.DateTimeField(null=True) Query: MyModel.values_list("some_datetime_field",flat=True).first() returns …
jadeidev
  • 194
  • 3
  • 13
0
votes
1 answer

Why is Django converting aware timestamp received from API request

My Django app receives POST API request with one of fields in body containing aware timestamp. If I log it's value right after deserialization I'm seeing the same time stamp but in different timezone. Here's example of submitted request body: { …
Stan Reduta
  • 3,292
  • 5
  • 31
  • 55
0
votes
1 answer

Django Model Default Datetime with Timezone Always Midnight

Current field in my model is as follows... from django.utils import timezone class Test(models.Model): assigned_date_time = models.DateTimeField( null=True, verbose_name='Assigned Date', default=timezone.now) When this object is…
Oh Great One
  • 374
  • 2
  • 17
0
votes
1 answer

Django doesn't convert the datetime using the right timezone

I'm struggling to figure out how timezone works in Django. On my systems I have all datetimes in UTC+00 even with a UTC+02 TIME_ZONE setting. timezone.get_default_timezone() …
0
votes
1 answer

Django: USE_TZ = False is not updating Postgres database setting

So I have some confusion regarding Use_Tz in Django. When the project was first started, USE_TZ was set to True, and we also had USE_I18N set to True. However, last week it was decided to set these settings to False. According to the docs here,…
Nathan
  • 291
  • 2
  • 5
  • 17
0
votes
1 answer

django form: error message with aware datetime

I'm trying to get add a datetime to my form error message. Unfortunately it is rendered in UTC (my TIME_ZONE), but should be in the current timezone. def clean(self): # print(get_current_timezone()) > Europe/Berlin cleaned_data =…
T. Christiansen
  • 1,036
  • 2
  • 19
  • 34
0
votes
1 answer

Why does time still show with UTC time zone instead of settings.TIME_ZONE?

I have a model that shows a short string in __str__() method of the model def __str__(self): return "Scheduled at %s" % (self.date_time.strftime("%B %d %Y %I:%M %p")) #Output: # it should…
Eu Chi
  • 533
  • 1
  • 6
  • 22
0
votes
1 answer

Django: Can not understand TIME_ZONE configuration

I have tested some timezone configuration to better understand about how django timezone works. But still cannot understand how it works. Have some questions and need your helps Q1. from django.utils import timezone from datetime import…
user3595632
  • 5,380
  • 10
  • 55
  • 111
0
votes
1 answer

Django timezone same day diff is not 0

test function from django.utils import timezone def date_diff_now(date): print(date) print(timezone.now()) print(date - timezone.now()) print((date - timezone.now()).days) Result 2018-02-07 17:46:36.442314+00:00 2018-02-07…
frlinw
  • 552
  • 6
  • 15
0
votes
0 answers

Django-rest-framework 'Expected a `date`, but got a `datetime`. Refusing to coerce, '

I am using django-rest-framework and trying to use my timezone date as the default for Date field but I am unable to do so. For DateTime field setting the default=timezone.now works perfectly but for Date field it gives the error in…