I have a date with timestamp stored in a variable and another variable which stores no. of days.
Var1=2014-12-11 12:54:21
Var2=5
In my unix script, I have to add the no. of days stored in var2 with the var1 date.
Var3=var1+var2=2014-12-16 12:54:21
Can you please advise if there is any unix function similar to dateadd MS SQL Server function. I tried using date -d argument,
but it is not supported in our environment.
Thank you in advance for your valuable suggestions.
Date, time arithmetic, math
1) gnu date
2) ksh (version 93, not 88) printf
3) date.pl (limited arith, but "date.pl -d '- 1 day'" works)
( http://www.unix.com/tips-tutorials/
239167-general-purpose-date-script.html)
4) dconv et al, e.g. ddiff
( dateutils: http://www.fresse.org/dateutils/ )
5) tm2tm (, OK in 32-bit; fails to compile in 64-bit)
( http://www.unix.com/shell-programming-scripting/
146216-date-difference-between-freebsd-linux.html#post302463136 )
6) perl custom (with function strftime)
7) date-cpan.pl, cpan perl date
( http://cpansearch.perl.org/src/CWEST/ppt-0.14/
src/date/date.jgross )
I believe the default ksh on AIX is a ksh88 version. To do date arithmetic with the ksh printf , you need a 1993 or later version of ksh . I believe many AIX systems have a another Korn shell installed as ksh93 that will do what is wanted here.
I'd be most interested if the ksh93 installed on AIX version 6 supports the %T printf format. Certainly in AIX 5.3, which comes with a much older ksh93 (version ksh93n I believe) this wasn't supported.
@Nikita1981, Please report if this command works for you: