Convert Date attribute to Quarter

1031
1
03-15-2012 01:51 AM
PilKwon
New Contributor II
I have feature classes have "Date" fields in date format and some of them are in String.
I'd like to convert them to Quarter and this is what i wrote...
please comments what parts got wrong and if anyone has better idea for codes, please let me know

# Process: Calculate Field

TESTING = if "Date" <= 03/31/2000 then 1
if "Date" >= 04/01/2000 and "Date" <= 06/30/2000 then 2
if "Date" >= 07/01/2000 and "Date" <= 09/30/2000 then 3
else 4

arcpy.CalculateField_management(Input_Feature, "Quarter", TESTING, "PYTHON", "")


and what if i have years thru 2000 - 2010 and want to convert them once, how do i code it ?
or is there way that i can only use the month and date and ..process for another years?
Tags (2)
0 Kudos
1 Reply
MarcinGasior
Occasional Contributor III
In attribute table create new integer Quarter field.
In Field Calculator choose Python parser and try a code which calculates quarter number based on month number:
(int(!Date![:2])-1)//3+1
0 Kudos