AnsweredAssumed Answered

Extract a portion of a date field: Field calculator

Question asked by tfagin on Oct 9, 2018
Latest reply on Oct 9, 2018 by tfagin

This is a statement as much as a question because I solved my issue. However, others may encounter something similar, so I will go ahead and post this.


I was looking for a DatePart equivalent for field calculator in ArcGIS Pro (e.g. in ArcMap could use something like DatePart("YYYY", [datefield])). 


I tried using SQL: EXTRACT(YEAR FROM "datefield"), which works for a query but apparently not for a field calculation. Anyone know why this may be?


Finally, I was able to use Python 3: !datefield!.strftime('%Y') (I discovered this is also case sensitive ('%y') only returns year without century.


The documentation on this seems to be poor (or I am not very good at finding it). Hopefully, this will help others who have a similar problem. This resource also proved to be very useful.