My django model datetime field is string. In this case, how to get data between two dates?
models.py
class asdf(models.Model):
recordDate = models.CharField(max_length=20,blank=True)
Change the 'recordDate' to DateField and use the following query:
asdf.objects.filter(recordDate__gte='2019-03-01', recordDate__lte='2019-03-09')
In order to get between range use filter this query:
models.asdf.objects.filter(recordDate__gte='start_date', recordDate__lt='end_date')
start_date
and end_date
may be string in date formats or datetime parsed object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With