Skip to content
Advertisement

Access Query to return custom quarters from a date field

If someone could help me out on this problem. This company’s quarter starts as follows where the numbers represent the months and the Q’s are the quarters.

Q1 = 9, 10, 11
Q2 = 12, 1, 2
Q3 = 3, 4, 5
Q4 = 6, 7, 8

I am trying to make a query a that returns the number 1, 2, 3, 4 for dates that fall within the quarters. I have researched and came across this approach but doesn’t work correctly because I don’t know how to handle Iif and Between functions.

Quarter: Iif(Month([MyDate]) Between 9 And 11, 1, Iif(Month([MyDate]) Between 12 And 2, 2, Iif(Month([MyDate]) Between 3 And 5, 3, 4)))

Advertisement

Answer

A simpler method uses datepart() — but 4 months later:

select datepart("q", dateadd("m", 4, mydate)) as my_quarter
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement