6

I am using ArcMap 10.0 and making a map where I symbolize on annual quarter (i.e. Q1 2013, Q2 2013, and so on by quarter through 2015).

If a date field contains this: 01/15/2013, and I wanted to create a new field called QUARTER, that would contain the quarter in which the date falls, how could I do that?

Right now I'm just definition querying a range of dates, but surely there is a way to just calculate Quarter, right?

1
  • 2
    Is the date field text or date field type?
    – artwork21
    Commented Feb 25, 2013 at 19:59

2 Answers 2

7

This python field calculator script should work:

def checkValue(field):
  myMonth = int(field.split('/')[0])
  myYear = field.split('/')[2]
  if myMonth <=3:
    return 'Q1-' + myYear
  elif myMonth >= 4 and myMonth <=6:
    return 'Q2-' + myYear
  elif myMonth >=7 and myMonth <=9:
    return 'Q3-' + myYear
  else:
    return 'Q4-' + myYear

enter image description here

Hope that helps.

2
  • 2
    You could simplify that a bit further by using if myMonth <=3: elif myMonth <=6: elif myMonth <=9: else:
    – kenbuja
    Commented Feb 25, 2013 at 21:31
  • @kenbuja, Good point!
    – artwork21
    Commented Feb 26, 2013 at 1:33
5

Here's a way using integer division:

def checkValue(field):
    m,d,y=field.split('/') #assumes date in some backward MM/DD/YYYY format, what's with that? ;)
    q=(int(m)-1)//3 + 1
    return 'Q%s - %s'%(q,y)
1
  • mmddyyy is not defined here.
    – blah238
    Commented Feb 26, 2013 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.