4

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,051
  • 5
  • 21
  • 44

3 Answers3

9

Try this

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

For more information on this : strftime

Sankar
  • 6,579
  • 2
  • 26
  • 47
2
from datetime import datetime
dt = datetime.strptime("09/12/16", "%d/%m/%y")
dt.strftime("%d-%B")
ctrl-alt-delete
  • 3,226
  • 2
  • 21
  • 34
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,009
  • 2
  • 20
  • 34