Syntax error with TruncDay

10 views
Skip to first unread message

Andrea

unread,
Feb 7, 2018, 5:28:22 AM2/7/18
to django...@googlegroups.com
I have the following model in Django 1.11.10:

class Test(models.Model):
  ...
  date_start = models.DateTimeField()
  ...

The following works fine:

Test.objects.annotate(day_start=TruncDate(ExpressionWrapper(F('date_start') - timedelta(hours=5), output_field=models.DateField()))

If I replace TruncDate with TruncDay or TruncMonth:

Test.objects.annotate(day_start=TruncDay(ExpressionWrapper(F('date_start') - timedelta(hours=5), output_field=models.DateField()))

I get the following error:

ProgrammingError: syntax error at or near "%"
LINE 1: ...TE_TRUNC('day', ("test_test"."date_start" - %s)) AS "d...

Is anyone able to reproduce the problem? The goal is to shift the `date_start` field in time before applying the `Trunc*` operation. Is that possible?

Thanks!
Andrea

Andrea Angelini

Zap 15
Tailored web solutions
www.zap15.com
Reply all
Reply to author
Forward
0 new messages