79 lines
1.6 KiB
Groff
79 lines
1.6 KiB
Groff
.TH computedate "" "" "/rdb Command"
|
|
.PC "Add given number of days to a date"
|
|
\fBcomputedate \fIdate days\fR
|
|
.PP
|
|
.II "date^arithmetic"
|
|
.II "arithmetic^date"
|
|
The command
|
|
.B computedate
|
|
adds days to a date, and displays the new date.
|
|
.I date
|
|
must be the format \fIYYMMDD\fR;
|
|
.I days
|
|
can be negative or positive.
|
|
.B computedate
|
|
displays the new date in the same format.
|
|
This is the best format for entering dates in a column
|
|
because they sort correctly and take only six characters.
|
|
.PP
|
|
Internally,
|
|
.B computedate
|
|
converts the date to
|
|
.BR julian ,
|
|
adds days, then converts the date back to
|
|
.BR gregorian .
|
|
Suppose we want to know the date 45 days from March 31, 1989.
|
|
We can type:
|
|
.DM
|
|
computedate 890331 45
|
|
.DE
|
|
.PP
|
|
This command returns the string:
|
|
.DM
|
|
890515
|
|
.DE
|
|
.PP
|
|
That is May 15, 1989.
|
|
.PP
|
|
Another trick is to combine the
|
|
.B todaysdate
|
|
and the
|
|
.B computedate
|
|
programs.
|
|
.B todaysdate
|
|
gives the date of today in the preferred format of \fIYYMMDD\fR.
|
|
For example, the following command shows us the date 45 days from today:
|
|
.DM
|
|
computedate `todaysdate` 45
|
|
.DE
|
|
.SH "Data Validation"
|
|
You can use
|
|
.B computedate
|
|
to validate a date.
|
|
If you add zero days to a date and get a different date, then
|
|
the original date was not valid.
|
|
For example, let's test the 32nd day of January 1989:
|
|
.DM
|
|
computedate 890132 0
|
|
.DE
|
|
.PP
|
|
This returns the string
|
|
.B 890201
|
|
or February 1, 1989.
|
|
As we expected, we received a different date.
|
|
We can test this with the following shell program:
|
|
.DM
|
|
if test $DATE = `computedate $DATE 0`
|
|
then
|
|
echo OK
|
|
else
|
|
echo Invalid DATE
|
|
fi
|
|
.DE
|
|
.SH "See Also"
|
|
.B
|
|
gregorian,
|
|
julian,
|
|
todaysdate
|
|
.R
|