[Answered ]-How to filter by date with datetimefield in Django with MYSQL

1👍

First you need to convert the date to a datetime object. In your case convert '2022-01-01' as:

from datetime import datetime

date_object = datetime.strptime("2022-01-01", "%Y-%m-%d")

# Then you can filter it as
qs = Data.objects.fitler(created_at__date__lte=date_object)

Leave a comment