I have following code:
import datetime
x = '2015-01-01'
date = datetime.datetime.strptime(x, "%Y-%m-%d")
print(date)
The problem is that I want to print date like "2015-01-01" and not "2015-01-01 00:00:00". How to print it without hours, minutes and seconds?
datetime objects have a date method which does this for you:
>>> import datetime
>>> x = '2015-01-01'
>>> date = datetime.datetime.strptime(x, "%Y-%m-%d")
>>> print(date.date())
2015-01-01
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With