python - Convert date to months and year -


from following dates how months , year using python

dates

           "2011-07-01 09:26:11"   //this showud display  "this month"            "2011-06-07 09:26:11"   //this should display june                        "2011-03-12 09:26:11"   //this should display march                        "2010-07-25 09:26:11"   // should display last year 

please let me know how these formats using python 2.4

import time import calendar  current = time.localtime()  dates = ["2011-07-01 09:26:11", "2011-06-07 09:26:11", "2011-03-12 09:26:11", "2010-07-25 09:26:11"]  date in dates:     print "%s" % date     date = time.strptime(date, "%y-%m-%d %h:%m:%s")      if date.tm_year == current.tm_year - 1:         print "last year"          elif date.tm_mon == current.tm_mon:         print "this month"      else:         print calendar.month_name[date.tm_mon] 

should ask for.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -