English

How To: Copy dates from a number field to a string field

Summary

This article discusses how to use the Field Calculator to copy a date in 'yyyjj' format to a string field in 'MMddyy' format. Where 'yyy' is the year with century and 'jj' is the day of the year. For example, in 2000123, 2000 equals the year and 123 equals the 123rd elapsed day of the year.

Procedure

  1. Open the table.
  2. Select Start Editing from the Table menu.
  3. Select Add Field from the Edit menu.
  4. In the Field Definition dialog box:
    a. Set Name to an appropriate name, for example 'Date'.
    b. Set Type to String.
    c. Set Width to 6 or desired number and click OK.
  5. Make the date field active.
  6. Type the following in the expression text box on the Field Calculator dialog box.
    Code:
    Date.Make([DateNumb].AsString,"yyyjj").SetFormat("MMddyy").AsString

    [O-Image]
    Note:
    DateNumb is the name of the number field containing the 'yyyjj' date value.

    [O-Image] Calculate New Date from number field
    Note:
    ArcView uses character codes to identify date and time components. 
    
    Format dates by specifying how the year, month, and day appear. A date value plug is one of the following:
M - the month as an integer from 1 to 12
MM - same as 'M', two digits with leading zeros
MMM - the short form of the month name
MMMM - the long form of the month name

d - the day of the month as an integer from 1 to 31
dd - same as 'd', two digits with leading zeros
ddd - the short form of the day name
dddd - the long form of the day name

y - the year without century
yy - same as 'y', two digits with leading zeros
yyy - the year with century, four digits with leading zeros
yyyy - same as 'yyy'
yyyyy - the year with century, not restricted to four digits

c - the century, without a leading zero
cc - the century, with a leading zero for single digit centuries
w - week of the year (Week 0 is first week with a Thursday)
ww - week of the year, two digits with leading zeros
D - numeric day of the week (Sunday = 1), one digit always
AD - AD or BC string depending upon the year
CE - CE or BCE string depending upon the year
J - Julian Day (days since January 1, 4713 BC)
j - day of the year
jj - day of the year, three digits with leading zeros