Lets say I have a sale model:
class Sale(models.Model):
total = models.DecimalField(max_digits=8, decimal_places=2, default=0)
sale_date = models.DateTimeField(auto_now_add=True)
Now, with each sale sale_date get its value saved in UTC, so if I try to group and sum all the sales by day:
report = Sale.objects.extra({'day':"date(sale_date)"}).values('day').annotate(day_total=Sum('total'))
I get all wrong becouse I expect each day in a different timezone (UTC-6).
Is there a way to get the correct sums in a specific tiemezone? Im working with MySQL.
Ah, this was a good challenge. I was able to test from PostGres, and I can confirm it is working. The MySQL code should be pretty close. However, there is a note on the CONVERT_TZ documentation:
MySQL (using CONVERT_TZ(dt, from_tz, to_tz))
PostGres: (using AT TIME ZONE)