Posted By

iloveitaly on 06/12/09


Tagged

day number python String suffix


Versions (?)

Get Day Suffix


 / Published in: Python
 

No switch statement in python (http://simonwillison.net/2004/May/7/switch/)

  1. def getDaySuffix(dayNumber):
  2. if dayNumber <= 3:
  3. return {1:"st", 2:"nd", 3:"rd"}[dayNumber]
  4. else:
  5. return "th"
  6.  
  7. # ex: June 12th
  8. nowTime = datetime.datetime.now()
  9. print nowTime.strftime("%B %d" + getDaySuffix(nowTime.timetuple()[2]))

Report this snippet  

You need to login to post a comment.