Django filter on Datetmefield

I have a model like below:

class example(models.Model):
   id = models.AutoField(primary_key=True)
   name = models.CharField(max_length=64)
   start_time = models.DateTimeField()
   end_time = models.DateTimeField()

And I have below query:

 a = example.objects.filter(
    name='John',
    start_time__gte=datetime.datetime.strptime('2022-07-26 2019:30:00','%Y-%m-%d %H:%M:%S')
    end_time__lte=datetime.datetime.strptime('2022-07-26 2019:35:00','%Y-%m-%d %H:%M:%S'))

For each minute i have a record so for top example i should give five record, but nothing returend.

The datetime string is not in the correct format. %H of datetime.datetime.strptime should not be greater than 23 (documentation).

It works if you provide a correct datetime string, for example:

a = example.objects.filter(
    name='John',
    start_time__gte=datetime.datetime.strptime('2022-07-26 19:30:00','%Y-%m-%d %H:%M:%S')
    end_time__lte=datetime.datetime.strptime('2022-07-26 19:35:00','%Y-%m-%d %H:%M:%S'))
Back to Top