How to convert string to date without time in python
I am converting string to date like this:
date=request.GET.get('date','')
if date:
date = datetime.strptime(date, "%m/%d/%Y")
print date
Prints:
2014-08-08 00:00:00
How can I get the date without 00:00:00?
+3
Atma
source
to share
2 answers
You have a "datetime" object, hence part of the time.
As @jonrsharpe mentioned in his comment, this
print date.date()
(ISO output)
or print date.strftime('%d/%m/%Y')
in your input format.
+7
ngulam
source
to share
from datetime import date
today = date.today()
print today.strftime('%d/%m/%Y')
0
phedoreanu
source
to share