I have two text fields (STRTTIME, ENDTIME) which are are formatted as military time with leading zeros. For example, 0540, 1655.

I want to calculate a new field with the time duration as integers (in minutes).

How can I go about this using the Field Calculator in ArcMap?

closed as off-topic by PolyGeo Jul 15 at 19:16

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

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    What have you tried? Please provide the function components as code blocks in your question. There will obviously be a modulus 100 in your calculations. – Vince Jul 15 at 16:09
  • 1
    Are all those times within the same day? Or will there be any cases where start on day 1 and end is on the next day? – Marcelo Villa Jul 15 at 16:29
  • Sorry for the delay. Yes, all the times are from the same day. Marcelo's code worked out. – Mercator Jul 16 at 17:44

Assuming all the times are from the same day, you can calculate the delta between the start time and the end time using the following Python function:

import datetime

def delta(start, end):
    start_dt = datetime.datetime.strptime(start, '%H%M')
    end_dt = datetime.datetime.strptime(end, '%H%M')
    return (end_dt - start_dt).seconds / 60

This function turns the strings into datetime objects so it can compute the delta between both times. Then it divides the number of seconds by 60 to return an integer with the minutes.

The date format is %H%M because:

%H - Hour (24-hour)

%M - Minute

You can run the function with the following expression: delta(!STRTTIME!, !ENDTIME!)


assuming they are the same day, you could just make a quick python function to calculate the time difference.


Codeblock set to:

def func(start, end):
  time_diff = end - start
  return time_diff

and expression being:


If it splits between days, you'll need some field to record how many days have passed.

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