Work with dates in a user-specified format


Instructions provided describe how to work with date values, in a string field, in a format specified. By default, dates in Arcview are represented by an 8-digit number in the format of YYYYMMDD.


  1. Open a table that contains a date field.
  2. Select Start Editing from the Table menu.
  3. Add a new string field called Date_String.

    A. Open the table and Start Editing, if necessary.
    B. Select Add Field from the Edit menu.
    C. In the Field Definition dialog box, define the following:
    a) Set Name to an appropriate name, for example 'Name'.
    b) Set Type to String.
    c) Set Width to an appropriate number, for example '32'.
    D. Click OK.
    E. Select Stop Editing from the Table menu and save the edits.

  4. Make the Date_String field active and click the Calculator button.
    [O-Image] Field Calculator Button
  5. Enter the following in the Expression text box:

    [Date].SetFormat( "M, d, yyyy").AsString

    [O-Image] Date.SetFormat Illustration
    Where [Date] is the field that contains the date value; .SetFormat changes the format of the date value; and .AsString creates a string object from a a date value.

  6. Define the date format of choice inside the parenthesis of the 'SetFormat' request. For example:

    [Date].SetFormat("M, d, yyyy").AsString


    [Date].SetFormat("MMM dd, yyy").AsString

    For more information on the various date formats, see the help topic 'Dates.'

  7. Click OK. Dates should be in the format specified.

    [O-Image] Date to String
    If there is a single field, and a different format is desired,
    use the SetFormat request on that field.

    To perform a query on dates contained in the String field, set the default date format to the format used for the date String field.

    1. Open a new Script Window.
    2. Copy the following line of code to the window, which may vary depending on the date format specified.


    3. Click the Compile button.
    [O-Image] Script compile button

    4. Click the Run button.
    [O-Image] Run compiled script button

    Then use one of these syntax samples to query the data information:

    ( [Date_String].AsDate >= "12, 03, 1996".AsDate)

    ( [Date_String].AsDate > "1972".AsDate)

    The AsDate request will create a date object from the string value.

Article ID:000004038

  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic