I'm using ArcGIS 10.3.3 and have a field containing a date as following format M/D/Y. I need to get the day of the week based on my date field.

I need to do this from the field calculator.

Example of my data:


def dayOfWeek(dField):
dow = datetime.strptime(dField , '%d/%m/%Y').strftime('%A')
return dow


but got error.

closed as off-topic by PolyGeo Sep 30 '16 at 17:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions relating to general Information Technology, with no clear GIS component, are off-topic here, but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software) and Database Administrators (relational databases)" – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    For coding questions, please include your best attempt code snippet within the question and let us know where you are stuck at. – artwork21 Sep 30 '16 at 17:01
  • 2
  • Please refer to the question (edited version) which I included my code. – Koush Sep 30 '16 at 17:04
  • 1
    What does the error message say? Also, is your actual code indented, or is it written unindented as displayed above? – recurvata Sep 30 '16 at 17:18
  • Even though this is using the Python Parser of the ArcGIS Field Calculator it seems likely to be a pure Python rather than GIS problem so I think you may be wise to research it using Stack Overflow. – PolyGeo Sep 30 '16 at 17:21

A VB Script will do that for you. Make sure your "Parser" is set to VB Script in the Field Calculator window. The two function you need are:

  • Weekday [returns numerical day of week 1-7]
  • WeekdayName [converts prior function the word for the day of the week]

If you put the following into the Filed Calculator it will write the word day of the week.


This should work in field calculator (tested on a text field with date string like m/d/y format):

import datetime
def getDay(value):
  day_dict = {0:'Monday',1:'Tuesday',2:'Wednesday',3:'Thursday',4:'Friday',5:'Saturday',6:'Sunday'}
  if value:
    dayInt = datetime.datetime(int(value.split('/')[2]), int(value.split('/')[0]), int(value.split('/')[1])).weekday()
    return day_dict[dayInt]

Not the answer you're looking for? Browse other questions tagged or ask your own question.