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
Solved! Go to Solution.
You can use the Arcade script
ISOWeek($feature.surveydate)
This is how it would look in the Field Calculator (with my data)
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
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.
or via python builtins. You just need to add an integer field to get the week number
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.
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 😉
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.
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.
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.