how to know which quarter does the current month belongs to ? (in python )
Question: I want to know to which quarter(Q1,Q2,Q3,Q4) does the current month belongs to
in python. I'm fetching the current date by importing time module as follows:

    
    
    import time
    print "Current date "  + time.strftime("%x")
    

any idea how to do it ?


Answer: [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) does
not know about quarters, but you can calculate them from the month:

  1. Use [`time.localtime`](https://docs.python.org/2/library/time.html#time.localtime) to retrieve the current time in the current timezone. This function returns a named tuple with year, month, day of month, hour, minute, second, weekday, day of year, and time zone offset. You will only need the month (`tm_mon`).

  2. Use the month to calculate the quarter. If the first quarter starts with January and ends with March, the second quarter starts with April and ends with June, etc. then this is as easy as dividing by 4 without remainder and adding 1 (for 1..3 // 4 == 0, 0 + 1 == 1, 4..6 // 4 == 1, 1 + 1 == 2, etc.). If your definition of what a quarter is differs (e.g. companies may choose different start dates for their financial quarters), you have to adjust the calculation accordingly.

