Date comparison

Date comparison

Hello all

I am writing a scrip that will take action so long as the date with in the file is older than 3 months. The file will contain multiple rows of data. Each row will probably start with the date. My question... What is the exact code that should be used for date comparison. I am thinking

if date A > current date
Then
do task...
else
fi

will Date A > current date surfice?

Well, YYYY-MM-DD HH:MM:SS date-time compares right as strings, so generally the quickest way to compare is to shuffle the bytes around to that format.

To generate the date 3 months ago in that format, you need date arithmetic, usually the realm of C/C++/JAVA/PERL/etc., with leap year knowledge for month lengths and such. Some of the later shells, like ksh93 and certainly bash, have date arithmetic. Is this 3 months = 90 days or varying?