I need to convert DateTime to Date in Python.
How to convert the DateTime 2020-04-14T18:30:00.000Z to date 2020-04-14 in Python Flask?
I need to convert DateTime to Date in Python.
How to convert the DateTime 2020-04-14T18:30:00.000Z to date 2020-04-14 in Python Flask?
There are two ways which you could do this, however, I will only focus on one. You can use:
import datetime
date = str(datetime.datetime.now())[:10]
print(date)
this code should yield a date in this format: YYYY/MM/DD
.
This works because you are essentially, by using [:10]
, cutting off all characters after character 9 of the string. For example,
X = "hello, world!"
# and then doing
print(X[:2])
would return:
he
Hope this answers your question!