Sure I could write this myself, but before I go reinventing the wheel is there a function that already does this?
I would suggest another arguably cleaner solution. If X is a datetime.datetime.now() instance, then the quarter is:
datetime.datetime.now()
import math Q=math.ceil(X.month/3.)
ceil has to be imported from math module as it can't be accessed directly.