Select to view content in your preferred language

Need help getting year from a date field (field calculator)

10645
14
06-03-2016 06:15 AM
RobBlash
Frequent Contributor

I have dates (in a date field) of mixed formatting (1/21/2006 4:19:20 AM, 12/27/2007, etc.). I need to populate an integer field with just the year.

Based on this thread I'm trying to work my way through it but I can't get it figured out

d = datetime.datetime.strptime(!InstallDate!, "%d/%m/%Y")
justyr = datetime.datetime(d.year)

Any help would be appreciated!

14 Replies
RobBlash
Frequent Contributor

Thanks! Looks like dateutil has a lot of useful functions, which I'm sure will be helpful as I learn more python and tackle more complex problems.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Robert Blash​, this "question" was created as a Discussion instead of a Question.  For future reference, it is best to mark questions as questions so people know you are seeking help instead of just sharing information.

RobBlash
Frequent Contributor

Makes sense, thanks for the tip.

0 Kudos
SanjaySinghNegi
New Contributor

!installdate!.year

TomyArdyansyah
New Contributor

thank you, it work on my case 

0 Kudos