问题
Sorry if its repetition of any old post. If so, kindly redirect.
Iam working on a shell script in AIX where we get a date from a file/command line. Now, i have to compare the current date with the input date and see the number of days difference.
I tried to google for its solution, but everywhere ended up with no proper solution.
Here i cant set the "date" variable, as iam not a root user.
Any inputs would be of great help.
回答1:
For anything slightly more complicated I'd suggest using datecalc (you can find a version at http://www.unix.com/unix-dummies-questions-answers/4870-days-elapsed-between-2-dates.html#post16559). It's implementable in most UNIX dialects.
回答2:
Gnu date has the --date option which satisfies your requirement. But since that's not available by default in AIX it wont help you. So you have to write your own code using awk/perl to achieve it. Check this question in stackoverflow which gives some idea about date arithmetic.
回答3:
echo $(($(($(date -d "2010-06-01" "+%s") - $(date -d "2010-05-15" "+%s"))) / 86400))
Source : Shell script to get difference in two dates
来源:https://stackoverflow.com/questions/9060519/date-manipulation-in-aix-shell-script