On Wed, 17 Apr 2002, "Thomas M. Albright" <[EMAIL PROTECTED]> wrote:
> 
> The dates are stored as mm/dd/yyyy. When the Payment Due date is equal
> to today + 90 days (IOW: 90 days before the due date) I want to send out
> an email containing an invoice to "Contact email".
> 
> Most of that I can figure out on my own. The only problem I really have
> is with the dates. I know 'date +%x` will output the current date as
> mm/dd/yyyy. `date +%j` will give me the day of the year (eg.: today is
> 107). Using that format quits working sometime in October tho. (10/3 is
> 276 + 90 = 366)

I like to write shell scripts that are portable to all Unixes, but using
gnu date is my one vice :-)  Indeed, I install it as "gdate" on most
machines I use so I can do time manipulation in sh scripts.

I think your problem can be solved by using the gnu date "n days",
"n days ago", etc, tricks in the -d "date string" option:

% date
Wed Apr 17 22:55:55 EDT 2002

% date -d "90 days ago"
Thu Jan 17 22:56:02 EST 2002

% date -d "90 days"
Tue Jul 16 22:56:06 EDT 2002

Works the same with "days" replaced by "seconds", "minutes", "years", etc.
It even does "n months ago" somehow.  There can also be a real date in the
-d string, e.g. -d "01/12/1989 90 days ago"


So I think your case would look like:

DUEDATE=`somehow read it in`

if [ "$DUEDATE" = `date +%m/%d/%Y -d "90 days"` ]; then
        echo "Please pay me $AMOUNT" | mail -s Invoice $CUSTOMER
fi

or something like that.  If instead of a test for "=" you need a test
for "<=" I suggest using +%s for *both* dates and doing a numerical compare.

Karl


*****************************************************************
To unsubscribe from this list, send mail to [EMAIL PROTECTED]
with the text 'unsubscribe gnhlug' in the message body.
*****************************************************************

Reply via email to