python - Django + Postgres Timezones -


i'm trying figure out what's going on timezone conversion that's happening in django.

my view code below, filters on date range , groups on day of creation:

def stats_ad(request):       start_date = datetime.datetime.strptime(request.get.get('start'), '%d/%m/%y %h:%m:%s')       end_date = datetime.datetime.strptime(request.get.get('end'), '%d/%m/%y %h:%m:%s')       fads = ad.objects.filter(created__range=[start_date, end_date]).extra(select={'created_date': 'created::date'}).values('created_date').annotate(total=count('id')).order_by("created_date") 

the sql query produced django when set variable of start "01/05/2013 00:00:00" , request end variable "11/05/2013 23:59:00":

select (created::date) "created_date", count("ads_ad"."id") "total" "ads_ad" "ads_ad"."created" between e'2013-05-01 00:00:00+10:00' , e'2013-05-11 23:59:59+10:00' group created::date, (created::date) order "created_date" asc 

if manually run on postgresql database, it's good, finds following:

created_date  total 2013-05-10    22 2013-05-11    1 

however if following:

for in fads:         recent_ads.append({"dates": a['created_date'].strftime('%d/%m/%y'), 'ads': a['total']}) 

it gives me following output:

[{"dates": "09/05/2013", "ads": 1}, {"dates": "10/05/2013", "ads": 22}] 

i'm @ loss @ why it's changed dates?

anyone got ideas?

cheers, ben

just through on this. of django 1.4, django supports timezone aware dates , times. perhaps it's possible conversion between local timezone , timezone data stored in (possibly gmt) taking place @ point. perhaps difference crosses international date line, in case dates may show differently.

django has interesting section describing new timezone support feature.
https://docs.djangoproject.com/en/1.4/topics/i18n/timezones/

that's came mind, anyway, when described problem. hope helps.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -