Select to view content in your preferred language

Extract week number from Date and Time field using Field Calculator in ArcPro

498
11
Jump to solution
03-11-2025 04:34 AM
RachelS
Frequent Contributor

Hi,

 

I'm hoping someone can help me to extract the week number from a date and time field using Field Calculator in ArcPro. I've tried a few codes I've found online but nothing is working.

My layer is called oyster, my fieldnames are surveydate and weeknumber.

Thanks

 

Rachel

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You can use the Arcade script

ISOWeek($feature.surveydate)

This is how it would look in the Field Calculator (with my data)

Snag_84ecaf.png

View solution in original post

11 Replies
DanielFox1
Esri Contributor

Hi @RachelS 

My reading of your query is you need to calculate the week number of the data you have, I found the following link which might 

https://developers.arcgis.com/arcade/function-reference/date_functions/#isoweek

This example from ArcGIS Survey 123 might also help 

https://community.esri.com/t5/arcgis-survey123-questions/how-to-calculate-the-week-number-of-a-date/...

RachelS
Frequent Contributor

Hi @DanielFox1 

I've tried the the isocalender but I'm getting an error posted in the reply to Dan,
The example from Survey123, I've implemented this in my Survey123 form so this won't be an issue going forward. I just have 2,000 records from the last few years I'm trying to get updated.

0 Kudos
DanPatterson
MVP Esteemed Contributor

date_ex.png

or via python builtins.  You just need to add an integer field to get the week number


... sort of retired...
RachelS
Frequent Contributor

Hi @DanPatterson 
Yes, this is the code I tried but I got the error message below.
My surveydate field is type 'Date' like 03/12/2024 16:44:00.000.
I thought it was because my week field was a string but when I created one that was an integer 'Long', I still get the error below.

RachelS_0-1741701762661.png

 

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

you date field was a string that was the problem, if you try it with a true date field as input and the output field (week) as integer (long) it should work, as in my example

And you can use python outside of the esri environment 😉

 


... sort of retired...
0 Kudos
RachelS
Frequent Contributor

Hi @DanPatterson 

That's interesting, how do I get the field to be a true date field? The properties of the field in ArcPro is 'Date' type.

I even created a new field in ArcPro as type Date, copied over the data and ran it but it still did the same.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If you shared some of the code samples you tried along with the errors or unexpected results, people could comment on why the code samples aren't working for you.  Also, sharing either example or sample data along with expected results helps people give better answers.

0 Kudos
RachelS
Frequent Contributor

Hi @JoshuaBixby 
The code I tried is in Dan's reply above but I get the error in the screenshot posted above.
The sample date is 03/12/2024 16:44:00.000 and in another field called week I'd just like to get it return 49.

I've 2000 of these records to update.

0 Kudos
KenBuja
MVP Esteemed Contributor

You can use the Arcade script

ISOWeek($feature.surveydate)

This is how it would look in the Field Calculator (with my data)

Snag_84ecaf.png