-2

I'm trying to convert

YYYY-MM-DD HH_MM_SS

to

YYYY-MM-DD 

example:

from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
i=0
var="2016-05-03"
while i < 5
new_date = datetime.strptime(var, "%Y-%m-%d") + relativedelta(days=i)
i=i+1
print(new_date)

in this example I would like to convert new_date to string YYYY-MM-DD. I have tried many option, none of them worked...

I thought it will be quite easy but it is not, how to handle with that ?

bazyl
  • 263
  • 1
  • 7
  • 17

1 Answers1

5

just change the print statement

print(new_date.strftime('%Y-%m-%d'))
harshil9968
  • 3,254
  • 1
  • 16
  • 26