views:

107

answers:

3

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
maybe datetime.datetime.now().day would give the today's day in the month
aeter
@aeter: Indeed. Added.
Mark Byers
Thanks.It turns out it wasn't about Python after all, but about arithmetics :)
stack_zen
+2  A: 

Check out the python calendar module

vito huang
Thanks.I knew about calendar and dateutil, but both didn't help me at that.
stack_zen
A: 

Not quite answer to your question, but for date manipulation http://labix.org/python-dateutil is often very useful.

Tomasz Zielinski