Printing Month And Date Using Python
I am trying to print only the month and date in python as following : 09-December 08-October How could I do that?
Solution 1:
Try this
import datetime
now = datetime.datetime.now()
print now.strftime("%d-%B")
For more information on this : strftime
Solution 2:
from datetime import datetime
dt = datetime.strptime("09/12/16", "%d/%m/%y")
dt.strftime("%d-%B")
Solution 3:
from datetime import date
d = date(2016, 12, 9)
d.strftime("%d - %A")
# 9 - Friday
# month day year
#d.strftime("%A %d %B %Y")
Post a Comment for "Printing Month And Date Using Python"