-1

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?

Murugan
  • 503
  • 4
  • 15
  • 1
    Does this answer your question? [How do I convert datetime to date (in Python)?](https://stackoverflow.com/questions/3743222/how-do-i-convert-datetime-to-date-in-python) – larsschwegmann Jul 03 '20 at 11:10

1 Answers1

1

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!