5

I am trying to print only the month and date in python as following :

09-December
08-October

How could I do that?

prudhvi
  • 1,141
  • 6
  • 23
  • 46

3 Answers3

10

Try this

import datetime
now = datetime.datetime.now()
print now.strftime("%d-%B")

For more information on this : strftime

Sankar
  • 6,908
  • 2
  • 30
  • 53
2
from datetime import datetime
dt = datetime.strptime("09/12/16", "%d/%m/%y")
dt.strftime("%d-%B")
ctrl-alt-delete
  • 3,696
  • 2
  • 24
  • 37
1
from datetime import date

d = date(2016, 12, 9)
d.strftime("%d - %A")
# 9 - Friday
# month day year
#d.strftime("%A %d %B %Y")
metmirr
  • 4,234
  • 2
  • 21
  • 34