Hi. Does python offer a way to easily get the current week of the month (1:4) ?
+2
A:
If your first week starts on the first day of the month you can use integer division:
import datetime day_of_month = datetime.datetime.now().day week_number = (day_of_month - 1) // 7 + 1
Mark Byers
2010-09-27 18:02:46
maybe datetime.datetime.now().day would give the today's day in the month
aeter
2010-09-27 18:11:19
@aeter: Indeed. Added.
Mark Byers
2010-09-27 18:14:05
Thanks.It turns out it wasn't about Python after all, but about arithmetics :)
stack_zen
2010-09-28 11:00:41
Thanks.I knew about calendar and dateutil, but both didn't help me at that.
stack_zen
2010-09-28 10:59:50
A:
Not quite answer to your question, but for date manipulation http://labix.org/python-dateutil is often very useful.
Tomasz Zielinski
2010-09-27 23:23:48