Format switches are -c for computer format ([yy]yymmdd); -e for European format (dd.mm.[yy]yy); and -u for U.S. format (mm/dd/[yy]yy). The first character of the switch defines the input date format; the second character, if any, defines the output date format. convertdate prepends the current century to input dates which contain 2-digit years. For example, the switch -cu converts dates from computer format to U.S. format; -e converts dates from European format to $DATEFMT, or to computer format if $DATEFMT is not defined.
If the environment variable $DATEFMT is set, convertdate will use it as a template for the output date format. $DATEFMT should indicate the order of the date elements; the number of bytes in each element, and the character used to separate the date elements, if any. The letter 'y' indicates a year byte; the letter 'm' indicates a month byte; and the letter 'd' indicates a day-of-month byte. For example, if $DATEFMT is m/d/yy, then dates will be converted to unpadded U.S. format (1/1/98): if it's mm/dd/yy, then single-digit month and day elements will be padded with a zero (01/01/98). Note that the year element of the date will never be output as less than 2 bytes, but if more than 2 are specified in $DATEFMT, 4 will be output: mm-dd-yyy will convert the input Julian date for New Years Day, 2000 to 01-01-2000. Finally, $DATEFMT does not necessarily need to include all 3 date elements: mm.dd is fine; so is YYYY or simply d.
\" .ft R
Note that the Date column is already in year-month-day order,
or computer format.
Let's remove the various separators:
we don't need to specify a format switch because both input and
output formats default to computer.
\" .ft C
$ convertdate Date < journal
Date Account Debit Credit Description
-------- ------- ----- ------ ----------------------------
19991122 101.0 25000 cash from loan
19991202 211.1 25000 loan number #378-14 BA
19991223 150.1 10000 test equipment from Zarkoff
19991224 101.0 5000 cash payment
19000110 211.2 5000 payable to Zarkoff Equipment
20000305 130.0 30000 inventory - parts from CCPSC
\" .ft R
Let's change the format of the date from computer to U.S.:
\" .ft C
$ convertdate -cu Date < journal
Date Account Debit Credit Description
---------- ------- ----- ------ ----------------------------------
11/22/1999 101.0 25000 cash from loan
12/02/1999 211.1 25000 loan number #378-14 Bank Amerigold
12/23/1999 150.1 10000 test equipment from Zarkoff
12/24/1999 101.0 5000 cash payment
01/10/1900 211.2 5000 note payable to Zarkoff Equipment
03/05/2000 130.0 30000 inventory - parts from CCPSC
If you do a lot of consistently non-standard date manipulation, it might be expedient to set your $DATEFMT to simplify the gregorian command. For example,
\" .ft C
$ echo $DATEFMT
m.d.yyyy
$ convertdate Date < journal
Date Account Debit Credit Description
--------- ------- ----- ------ ----------------------------------
11.22.1999 101.0 25000 cash from loan
12.2.1999 211.1 25000 loan number #378-14 Bank Amerigold
12.23.1999 150.1 10000 test equipment from Zarkoff
12.24.1999 101.0 5000 cash payment
1.10.1900 211.2 5000 note payable to Zarkoff Equipment
3.5.2000 130.0 30000 inventory - parts from CCPSC