Wednesday, May 25, 2011

Querying for Django date ranges

MySQL provides a simple DATE() function that allows you to convert a DATETIME (, but how does one do so in Django?

Apparently, you have use the __range and use datetime.datetime.combine(), as well as datetime.time.min and datetime.time.max to do things:

{'date_field__range': (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))}

`myapp_mytable`.`date` BETWEEN 2011-05-25 00:00:00 and 2011-05-25 23:59:59)'

No comments:

Post a Comment