Making simple date field calculations using the field calculator
There are two ways to perform field calculations in ArcMap: through the attribute table or by using the Calculate Field geoprocessing tool. Both options use the same functionality.
To calculate date values to a field in the attribute table, follow the steps below:
- Click the Editor menu on the Editor toolbar and click Start Editing.
You can make calculations without being in an editing session; however, in that case, there is no way to undo the results.
- Click the List by Source button on the table of contents.
- Right-click the table or layer in the table of contents and choose Open Attribute Table.
Right-click the heading for the date field and click Field Calculator.
If there is no field for date values, add a new date field by clicking the Options button and clicking the Add Field option. To add a new field, you need to exit the editing session.
- Use the Fields and Functions lists to build a date field calculation expression. You can also edit the expression in the text area below or type your own valid expression.
- Click OK.
Any Python or VBScript datetime function can be used to calculate a date. Optionally, a number sign (#) can be used to denote a date in the same way that double quotation marks (") are used to denote a string. Note that the number sign is not locale aware and can only work properly with U.S. English date structures. For other locales, use DateSerial() or another locale-specific function.
There is a numeric representation for each date and time. A date of December 30, 1899, has a universally agreed-on value of 0. If you calculate a date field to 1.5, you get December 31, 1899 12:00:00 PM. The number to the left of the decimal (in this case, 1) represents the day of the year. Negative numbers represent days prior to December 30, 1899, and positive numbers represent days after December 30, 1899. The number to the right of the decimal represents time, with 0 being 12:00:00 AM and .5 being 12:00:00 PM. This allows you to do calculations that mix numbers and dates. Suppose your data has the service date for water meters and you want to generate a report with the next service date in 30 days. To determine the date, you could use the following VBScript calculation:
Next_Service_Date = service_date + 30