Date manipulation in AIX shell script

吃可爱长大的小学妹 提交于 2020-01-06 14:34:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!