alan@cms2.UUCP (Alan McCain) (10/13/90)
Can anyone give me some ideas of calculating the ages of people? I have an application where I am generating a report using awk and part of the report is figuring out the age of someone using their birth date in the form yymmdd. I would like a solution in awk but am welcome to other suggestions, too. Thanks! Alan -- Alan McCain Christian Medical & Dental Society UUCP: cms2!alan INTERNET: alan@cms2.lonestar.org
jpr@jpradley.uucp (Jean-Pierre Radley) (10/22/90)
In article <354@cms2.UUCP> alan@cms2.UUCP (Alan McCain) writes: >Can anyone give me some ideas of calculating the ages of people? I have an >application where I am generating a report using awk and part of the report >is figuring out the age of someone using their birth date in the form >yymmdd. I would like a solution in awk but am welcome to other suggestions, >too. > The late Fred Buck was handed a hypothetical manual page for something that would do date calculations. So he wrote the program to fit the manual page. It's a bit too much to include all of it here (and it's C source, not shell language), so I'm emailing it to you. But here's the man page: Name datecalc - date math filter Syntax datecalc [-mdy] {+|-}offset [date] or datecalc -i [-mdy] [{+|-}offset] basedate [newdate] Description Datecalc performs addition or subtraction upon the date passed to it, and returns the calculated date to standard output. If no date is specified on the command line, datecalc reads standard input for a list of dates separated by newlines, performs the specified arithmetic on each date in the list, and sends the calculated date(s) to standard output. The default order for day, month and year on input is month, day, year. If the "-mdy" argument is given, then the order of month, day and year on input is taken to be whatever order the letters 'm', 'd' and 'y' appear in the command-line argument. So "-mdy" means "month, then day, then year" and is the same as the default; "-dmy" means "day, then month, then year" and so forth. The offset must be preceded by a plus or a minus sign. The format of date, whether on the command line or in standard input, is up to the user. If day, month, and/or year are not separated by any non-numeric characters, then each field must contain at least two characters ("03" instead of "3"); if delimiters are used, single-digit fields are permissible. If alphabetic format is used for the month, output will mimic input format but the month name will be no longer than three characters. If the "-i" switch is present, and if it's present it has to be the first command-line switch, then the whole deal is different. The "-i" stands for "interval", and with this switch, this program will report either the number of days separating two specified dates, or the latter of the two dates if the interval between the dates is greater than or less than the specified 'offset', where 'offset' can be positive or negative. If the "-i" switch is present, then a basedate must be specified on the command line. If the "newdate" isn't specified on the command line, then standard input is examined for a list of newdates to compare with the command-line basedate. The type of output when "-i" is present depends on whether an interval argument is also present: if no interval is specified, then the output consists of the number days separating the basedate and the new date. If an interval argument, preceded by a plus sign or a minus sign, is specified, then the output consists of the new date if the new date is outside (plus sign) or within (minus sign) the specified interval from the basedate. An easy way to remember this is that with the "-i" option, an offset of "+x" means "report any received dates greater than x days distant from the basedate"; an offset of "-x" means "report any received dates less than x days distant from the basedate"; and no offset at all means "report the number of days between the basedate and the newdate." Examples datecalc -dmy +20 27-8-88 returns 16-9-88 datecalc +20 8/27/88 returns 9/16/88 datecalc +20 08-27/88 returns 09-16/88 datecalc +20 August 27, 1988 returns Sep 16, 1988 datecalc -ydm +20tS Scans standard input for dates in year, day, month format, and returns the date 20 days after each input date, in the format of each input date datecalc -i -7 9/1/88 9/28/88 returns nothing, because 9/28 isn't within 7 days of 9/1 datecalc -i +7 9/1/88 9/28/88 returns 9/28/88 datecalc -i 9/1/88 9/28/88 returns 27 datecalc -i -dmy 1-Sep-88 Scans standard input for dates in day, month, year format, and reports for each input date the number of days' diff- erence between that date and 1-Sep-88 Notes Valid dates range only from 1970 through 1999. Author Fred Buck -- Jean-Pierre Radley HIGH-Q jpr@jpradley CIS: 72160,1341