How to extract month from mm/dd/yyyy date field in ArcGIS Pro?

5280
3
Jump to solution
12-15-2018 03:26 PM
ChrisSpadi1
New Contributor II

I have an attribute table with an ALARM_DATE field (mm/dd/yyyy) (data type: Date) and I want to extract only the month from it to a new field.

What is the simplest way to achieve this in field calculator or python 3?

1 Solution

Accepted Solutions
ChrisSpadi1
New Contributor II

Thanks everyone. I ended up figuring it out with an Arcade solution using the date function Month.

date field is !ALARM_DATE!

new field I want only the month number is !Month_!

All you need to do is use the field calculator for new field ---->         !Month_! (integer)

Choose Arcade, enter Month($feature.ALARM_DATE), this returns values of the month 0 - 11 in Month_ field.

Use field calculator again on !Month_! with Python to add 1 to make it 1-12,   -----> !Month_! + 1

View solution in original post

3 Replies
DanPatterson_Retired
MVP Emeritus

An example of a time field in a table called Timetest  (python parser)

int(!Timetest!.month)‍‍

Now via example

n = datetime.datetime.now()

n
datetime.datetime(2018, 12, 15, 20, 11, 32, 784152)

type(n)
<class 'datetime.datetime'>

dir(n)

[... snip, 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst', 'fold',
 'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat', 'isoweekday',
 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution',
 'second', 'strftime', 'strptime', 'time', 'timestamp', 'timetuple', 'timetz',
 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset',
 'utctimetuple', 'weekday', 'year']

n.month  # ---- which is now an integer
12

shan_sarkar
Occasional Contributor III

Have you tried using the Left () available in the Field Calculator under the String() tab?

How to extract Middle, Left, or Right characters in Calculate Field tool 

Calculate Field Python examples—Data Management toolbox | ArcGIS Desktop 


~Shan
0 Kudos
ChrisSpadi1
New Contributor II

Thanks everyone. I ended up figuring it out with an Arcade solution using the date function Month.

date field is !ALARM_DATE!

new field I want only the month number is !Month_!

All you need to do is use the field calculator for new field ---->         !Month_! (integer)

Choose Arcade, enter Month($feature.ALARM_DATE), this returns values of the month 0 - 11 in Month_ field.

Use field calculator again on !Month_! with Python to add 1 to make it 1-12,   -----> !Month_! + 1