1from django.utils.dateparse import parse_date, parse_datetime
2
3# For only Date
4date_str = "2021-04-07"
5date = parse_date(date_str)
6# For DateTime
7datetime_str = "2021-09-10T18:40:54"
8date = parse_date(datetime_str)
9
10OR
11
12date_str = "2021-04-07"
13datetime.datetime.strptime(date_str, "%Y-%m-%d").date()
14