EJSuh EJSuh - 2 months ago 8
Python Question

Need help on datetime manipulation in python

import datetime
today = datetime.date.today()
print ('Today is: ' + str(today))

//returns Today is: 2016-10-06


How could I manipulate the output to look like this:
"Today is: October 6, 2016"

Answer

Based on datetime.strftime() documentation:

import datetime
today = datetime.date.today()
print('Today is: ' + today.strftime("%B %d, %Y")) # Today is: October 06, 2016

Where:

  • %B - Month as locale‚Äôs full name
  • %d - Day of the month
  • %Y - Year with century as a decimal number