Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

Thanks in advance!

share|improve this question
2  
Is the date field text or date field type? –  artwork21 Feb 25 '13 at 19:59
add comment

2 Answers 2

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.

share|improve this answer
2  
You could simplify that a bit further by using if myMonth <=3: elif myMonth <=6: elif myMonth <=9: else: –  kenbuja Feb 25 '13 at 21:31
    
@kenbuja, Good point! –  artwork21 Feb 26 '13 at 1:33
add comment

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)
share|improve this answer
    
mmddyyy is not defined here. –  blah238 Feb 26 '13 at 4:37
    
Fixed now. Changed variable name without checking I'd changed ALL of them... –  Luke Feb 26 '13 at 4:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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