Calculating an attribute to the number of days between two dates

There are two scripting languages for calculating values in ArcMap. You can use either VBScript or Python, and both are available through the Calculate Field tool.

To calculate the number of days between two dates with VBScript, follow these steps:

Steps:
  1. Click the Editor menu on the Editor toolbar and click Start Editing.
  2. Click the List by Source button on the table of contents.
  3. Right-click the table or layer in the table of contents and choose Open Attribute Table.
  4. Right-click the heading for the field to show the number of days between the date and the present date and click Field Calculator.

    You can make calculations without being in an editing session; however, in that case, there is no way to undo the results.

  5. In the field calculator text box, enter the following calculation VBScript expression:

    DateDiff("d", [date_field], Now())
    

    NoteNote:

    In the code above, date_field should be changed to the name of your attribute table's date field name.

  6. Click OK.

    The number of days between the date in the date field and the current date are placed in the specified field.

TipTip:
Valid dates range from January 1, 0100, to December 31, 9999. Keep in mind that date calculations using and producing date values earlier than the year in which the Gregorian calendar was adopted may not be appropriate.

Related Topics

3/18/2014