Date Incremental in AIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date Incremental in AIX
# 8  
Old 11-12-2013
I tested on GNU bash, version 4.2.25(1)-release (i686-pc-linux-gnu)

if you have ksh93 use this

Code:
#!/bin/ksh93

a=01/Apr/13
for((i=0;i<5;i++))
do
        printf "%(%d/%b/%y)T\n" "$a + $i day"
done

Code:
$ ksh date.ksh
01/Apr/13
02/Apr/13
03/Apr/13
04/Apr/13
05/Apr/13

OR else in #2 make n=$(echo "${a:0:2}-1" | bc) to n=0 Since I just wanted to use same variable a for vaiable n so did like that.

Let me know whether it's working or not

Last edited by Akshay Hegde; 11-12-2013 at 03:58 PM.. Reason: more info and color
# 9  
Old 11-12-2013
tried same
Code:
for((i=${a:0:1};i<5;i++))

getting error
Code:
`(' unexpected.


Last edited by Scott; 11-12-2013 at 07:20 PM.. Reason: Code tags
# 10  
Old 11-12-2013
Quote:
Originally Posted by onesuri
tried same
for((i=${a:0:1};i<5;i++))
getting error
`(' unexpected.
How did you try ? which one you used bash or ksh ?
# 11  
Old 11-12-2013
ksh ..
# 12  
Old 11-12-2013
No idea about AIX if you have copied #8 code properly it should work.

and which ksh ?
run this on terminal
Code:
$ which ksh
$ ksh --version

# 13  
Old 11-12-2013
/usr/bin/ksh
# 14  
Old 11-12-2013
I've worked on AIX 5.3 before and the ksh93 was version 93n which doesn't support the %T printf formatter.

Usual solution is to either use perl code or download the coreutils package from the AIX linux toolbox site. Once it's installed a GNU date command that supports the --date option can be found /opt/freeware/bin/

---------- Post updated at 08:09 AM ---------- Previous update was at 07:39 AM ----------

If you don't have ability to install packages this perl script should work OK on AIX (don't have access to AIX to test for you):

Code:
#! /usr/bin/env perl
use Time::Local;
use POSIX qw(strftime);

my %mon;
@mon{qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/} = 0..11;

my ($dd, $mmm, $yy) = split(/[-\/ ]/, $ARGV[0]);
print strftime("%d/%b/%y\n", localtime(timelocal(0,0,0,$dd,$mon{$mmm},2000 + $yy) + $ARGV[1]*24*60*60));

Usage:
Code:
$ ./dateadd.pl 01/Apr/13 20
21/Apr/13

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

How do you keep your AIX skills up to date?

I am very curious to find out how AIX admins keep up to date and refreshed with all of the options and features of AIX without having access to a test environment? Usually going on a course requires practice otherwise the knowledge gained can get lost very quickly. How do you practice for the... (5 Replies)
Discussion started by: Colin_Fearnley
5 Replies

2. UNIX for Dummies Questions & Answers

Date format change in AIX

Hi I have a date format in a variable as Apr 7 03:35:59 EDT 2016. how do i change it to 04/07/2016 03:35:59 EDT format (5 Replies)
Discussion started by: sushma123
5 Replies

3. Shell Programming and Scripting

Date formatting in AIX

Can you help in formating the date command in aix to get the following format Oct 11 21:52 Fri Oct 11 21:52:01 PDT 2013 Required output: Oct 11 21:52 Fri Oct 11 21:52:01 PDT 2013 (1 Reply)
Discussion started by: chandu123
1 Replies

4. UNIX for Advanced & Expert Users

Subtract days to a date in AIX 5.3

good afternoon, can someone help me, I need to make a script where n subtract days to a date. I am using AIX 5.3. Greetings. (4 Replies)
Discussion started by: systemoper
4 Replies

5. Shell Programming and Scripting

How to display yesterday Date in AIX

Hi, I need help to display the yesterday date in format mentioned below: 2012-06-26-PMI tried this but it displays current date: `date +%Y-%m-%d-%p` (9 Replies)
Discussion started by: aroragaurav.84
9 Replies

6. AIX

Get Next month in AIX from curent date in unix AIX

How could we derive teh Next month in MON-RR format from current date ie sysdate in UNI AIX sheel script.I coould get a command but i supports only inLinux susse andnotin AIX. I need for Unix AIX.Pls Help. Regards Shiv (2 Replies)
Discussion started by: SHIV75
2 Replies

7. Shell Programming and Scripting

current date - one month in AIX

Hi, i unable to get the last month date in AIX. current date - one month Based on the forums tried but did not find the relevent information. Any help grealy appriciated. Thanks Suri. (3 Replies)
Discussion started by: onesuri
3 Replies

8. Shell Programming and Scripting

To Get the day of given date in aix

Hi, Can any one help to find out the day for the given date in AIX. If we giving date as "YYYYMMDD" it should display its day. eg:if the input is "20120103", expected output is "tuesday" :wall: Pls help (7 Replies)
Discussion started by: novaothers
7 Replies

9. AIX

How to get the date yesterday in AIX sh

Hi, In AIX sh, how to return the date of yesterday in format of %Y%m%d, YYYYMMDD. i.e. if today is 20080704, I want it return 20080703. Can anyone help? Thanks! Victor Cheung (4 Replies)
Discussion started by: victorcheung
4 Replies

10. AIX

date command in AIX

hi, i have a simple question in linux: date '+%s' -r filename--------> gives the file age in seconds i want the option to be used with date command in AIX ?? (1 Reply)
Discussion started by: ali560045
1 Replies
Login or Register to Ask a Question