Attribute Rule - Year from Date & Time field

1966
6
Jump to solution
02-09-2022 12:20 PM
JessicaJThompson
Occasional Contributor II

Hello! (ArcGIS Pro 2.9.1)

I am trying to sort out what I am doing wrong with my attribute rule. This is my first time dabbling with it. 

I have two fields. One is a date and time field. This is filled by a survey. The Year field is where I want to apply an attribute field. I want it to only have the four digit year from the date and time field.  However, the year that is returning is 1899. 

JessicaJThompson_0-1644437769392.png

JessicaJThompson_1-1644437838208.png

I have tried a few variations in the expression but none are working. 

JessicaJThompson_2-1644438004038.png

 

Thank you for your kind help to solve this. 

Cheers,

Jessica Thompson

0 Kudos
2 Solutions

Accepted Solutions
JessicaJThompson
Occasional Contributor II

@jcarlson Thank you for taking time to help me. 

Ok. that is what I put in! So we are getting close. 

JessicaJThompson_0-1644503034156.png

JessicaJThompson_3-1644503497860.png

 

JessicaJThompson_1-1644503298151.png

The very first time (when it was still a date field) it returned 1899. This time it returned a null value.

JessicaJThompson_2-1644503445244.png

 

 

 

View solution in original post

0 Kudos
jcarlson
MVP Esteemed Contributor

If you just run a field calculation, does it work? Or are you manually triggering the rule some other way? I notice your rule is only set to fire on feature edits.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
6 Replies
jcarlson
MVP Esteemed Contributor

Your YEAR field is a date field, but the Year function in Arcade returns a numeric value. In order to call something like Year(Now()) and get 2022 stored in your field, it needs to be a different type.

Since Date fields are really just integers representing "milliseconds since <your DB's reference timestamp>", you'll probably end up with a bunch of values just a few seconds after midnight on that reference timestamp, the way your field is set up now.

- Josh Carlson
Kendall County GIS
JessicaJThompson
Occasional Contributor II

Thank you @jcarlson . I added a test field and made it numeric. Tried the Year(Now()) but that still didnt work. I know I'm not doing it correctly.

Ultimately I need to know if I can pull the year from a date and time field, and how I can do that in attribute rules. 

So say for my date and time (field name TIME_DATE) field which is formatted as in the photo below.

JessicaJThompson_0-1644502129949.png how would I write the Arcade expression to pull just the year out, and have the column formatted as just the year and not an entire date. 

Thank you for your help!

Cheers,

Jessica 

0 Kudos
jcarlson
MVP Esteemed Contributor

If you have a field "TIME_DATE" and you want to populate another column "YEAR" with the year, it would just be as simple as

Year($feature.TIME_DATE)

just like you have written in your original post.

What did your test field look like when you created it? Did it not fill in with numeric values?

- Josh Carlson
Kendall County GIS
0 Kudos
JessicaJThompson
Occasional Contributor II

@jcarlson Thank you for taking time to help me. 

Ok. that is what I put in! So we are getting close. 

JessicaJThompson_0-1644503034156.png

JessicaJThompson_3-1644503497860.png

 

JessicaJThompson_1-1644503298151.png

The very first time (when it was still a date field) it returned 1899. This time it returned a null value.

JessicaJThompson_2-1644503445244.png

 

 

 

0 Kudos
jcarlson
MVP Esteemed Contributor

If you just run a field calculation, does it work? Or are you manually triggering the rule some other way? I notice your rule is only set to fire on feature edits.

- Josh Carlson
Kendall County GIS
0 Kudos
JessicaJThompson
Occasional Contributor II

Hello @jcarlson 

It worked when I did a field calculate - so I added a new survey record and IT WORKED!! 

Thank you thank you!