By default, gregorian dates are output in yyyymmdd format (for example, 19920905 is 5 Sep 1992).
If the environment variable $DATEFMT is set, gregorian 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. The format options (-e, -u, -c) take precedence over $DATEFMT.
$ cat journal Date Account Debit Credit Description -------- ------- ----- ------ ---------------------------- 99 11 22 101.0 25000 cash from loan 99.12.02 211.1 25000 loan number #378-14 BA 99-12-23 150.1 10000 test equipment from Zarkoff 99/12/24 101.0 5000 cash payment 000110 211.2 5000 payable to Zarkoff Equipment 20000305 130.0 30000 inventory - parts from CCPSCLet's add 45 days to each of the dates by converting the date column to Julian format, computing the 45 day addition, and converting the date column back to Gregorian format:
$ julian Date < journal | compute 'Date += 45' | gregorian Date Date Account Debit Credit Description -------- ------- ----- ------ ---------------------------- 20000106 101.0 25000 cash from loan 20000116 211.1 25000 loan number #378-14 BA 20000206 150.1 10000 test equipment from Zarkoff 20000207 101.0 5000 cash payment 19000224 211.2 5000 payable to Zarkoff Equipment 20000419 130.0 30000 inventory - parts from CCPSC
Note that the fifth record contains the date February 24, 1900. Considering the surrounding dates, this is probably a user mistake: because the short year format was used as julian input, the current century was supplied. While date computations appear correct in the short form, they may not be if you're crossing the century boundary. As we near the next millenium, use of the long form for the year is highly recommended.
Let's subtract 2 weeks from the date and change the format to U.S.:
$ julian Date < journal | compute 'Date -= 14' | gregorian -u Date Date Account Debit Credit Description -------- ------- ----- ------ ---------------------------- 11/08/1999 101.0 25000 cash from loan 11/18/1999 211.1 25000 loan number #378-14 BA 12/09/1999 150.1 10000 test equipment from Zarkoff 12/10/1999 101.0 5000 cash payment 12/27/1899 211.2 5000 payable to Zarkoff Equipment 02/20/2000 130.0 30000 inventory - parts from CCPSCIf 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,
$ echo $DATEFMT m.d.yyyy $ julian Date < journal | gregorian Date 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
Note: A simpler way to change just the format of date columns is with the convertdate command. Y2K NOTE: