Roopesh Majeti
Roopesh Majeti

Reputation: 554

Date manipulation in AIX shell script

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.

Upvotes: 0

Views: 7006

Answers (3)

chanchal1987
chanchal1987

Reputation: 2367

echo $(($(($(date -d "2010-06-01" "+%s") - $(date -d "2010-05-15" "+%s"))) / 86400))

Source : Shell script to get difference in two dates

Upvotes: 0

telcopro
telcopro

Reputation: 148

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.

Upvotes: 1

Raghuram
Raghuram

Reputation: 3967

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.

Upvotes: 0

Related Questions