# Converting date fields

Suppose you had input records that looked like this:
``````03212009 Sacramento
05172008 Los Angeles
12302008 Morgan Hill
08132009 Palo Alto``````
The first field is a gregorian date in 'mmddccyy' form, but you'd actually like to reformat it into a julian date in 'ccyy/ddd' form. You can use the following statements to convert the date field to the form you want:
``  OUTREC BUILD=(1,8,Y4W,TOJUL=Y4T(/),X,10,15)``
The results produced for this OUTREC statement are:
``````2009/080 Sacramento
2008/138 Los Angeles
2008/365 Morgan Hill
2009/225 Palo Alto     ``````
Y4W and Y4T are two of DFSORT's 4-digit year date field formats. Y4W indicates a date value with the year (ccyy) last such as 'mmddccyy' or 'dddccyy' whereas Y4T indicates a date value with the year first such as 'ccyymmdd' or 'ccyyddd'. TOJUL is one of the conversion keywords that can be used with date fields. You can use any of the following after p,m,Y4x or p,m,Y2x to convert a CH, ZD or PD 4-digit or 2-digit year date in one form to a corresponding CH, ZD or PD 4-digit or 2-digit year date in another form or to a corresponding day of the week:
• TOJUL=Yaa - converts to a julian date without a separator (for example, P'2009007').
• TOJUL=Yaa(s) - converts to a julian date with a separator (for example, C'325-2008').
• TOGREG=Yaa - converts to a gregorian date without separators (for example, Z'091121').
• TOGREG=Yaa(s) - converts to a gregorian date with separators (for example, C'2009.09.21').
• WEEKDAY=CHAR3 - converts to a 3 character day of the week (for example, C'WED' for Wednesday).
• WEEKDAY=CHAR9 - converts to a 9 character day of the week (for example, C'THURSDAY ' for Thursday).
• WEEKDAY=DIGIT1 - converts to a 1 digit indicator for the day of the week (for example, C'2' for Monday).
• WEEKNUM=USA - converts to an integer in the range of 1 to 54 that represents the week of the year.
• WEEKNUM=ISO - converts to an integer in the range of 1 to 53 that represents the week of the year.
• Age=YMD – converts to a 8 byte integer which has duration in years (0-9999), months (00-12), and days (00-31).
• Age=YM – converts to a 6 byte integer which has duration in years (0-9999), months (00-12).
• Age=YD – converts to a 7 integer which has duration in years (0-9999), days (00-366).

For complete details on converting from one type of date field to another, see z/OS DFSORT Application Programming Guide.