Just posting a correction to the parent post, putting the year as the first parameter to datetime.datetime():
def byYear(column, year):
return AND(column >= datetime.datetime(year, 1, 1),
column < datetime.datetime(year + 1, 1, 1))
def byYearAndMonth(column, year, month):
return AND(column >= datetime.datetime(year, month, 1),
column < datetime.datetime(year + (month + 1) / 13,
month % 13 + 1, 1))

