You can use the python time module in the standard library import time month_int = time.strptime(month_str, "%b").tm_mon
The %b formatter assumes your month_str is a valid abbreviated month str (e.g. 'apr'). Check the time docs here: http://www.python.org/doc/2.5.2/lib/module-time.html On Feb 15, 7:31 am, harryos <oswald.ha...@gmail.com> wrote: > hi > In my view I am taking user input string for month( like 'jan','feb') > and want to search the db for objects with those months as published > time. > > def entry_archive_for_month(request,year,month): > > entryset=Entry.objects.filter(pub_time__year=year,pub_time__month=month) > > obviously this will cause ValueError since month='jan' but > pub_time__month should be an integer > > Is there any way I can convert the month string into integer?Do I have > to create a dictionary with all lowercase month strings and then call > a function to return the matching integer?I would like to know if > there is a better way. > > thanks > harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.