Answers for "how to transfomr a value string into date django"

1

convert string to date django

from django.utils.dateparse import parse_date, parse_datetime

# For only Date
date_str = "2021-04-07"
date = parse_date(date_str)
# For DateTime
datetime_str = "2021-09-10T18:40:54"
date = parse_date(datetime_str)

OR

date_str = "2021-04-07"
datetime.datetime.strptime(date_str, "%Y-%m-%d").date()
Posted by: Guest on September-12-2021

Code answers related to "how to transfomr a value string into date django"

Python Answers by Framework

Browse Popular Code Answers by Language