Date Incremental in AIX

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date Incremental in AIX
# 15  
Old 11-13-2013

COuld you please explain the below ?
my %mon;
@mon{qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/} = 0..11;

# 16  
Old 11-13-2013
Parameter number 5 of localtime() is month number (0 for Janurary, 1 for Feburary ... 11 for December). So we need to convert the input string from a 3 character string (Jan, Feb, etc) to and integer from 0 to 11.

In a normal 3rd generation language (like C) we would have to use 12 if statements or a big case statement to assign the month number for each string (eg. if (strcmp(mmm, "Jun") == 0) mon=5;). Perl has a nifty datatype called an associative array, this is like a normal array except the index value can be a string. I use these to lookup them month string and fetch then required number:

my %mon; Here I've defined an associative array called mon.

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

This creates array elements $mon{"Jan"}=0, $mon{"Feb"}=1 thru $mon{"Dec"}=11

The above statement can be written a number of ways for example:

@mon{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);

%mon = ("Jan", 0, "Feb", 1, "Mar", 2, "Apr", 3, "May", 4, "Jun", 5, "Jul", 6, "Aug", 7, "Sep", 8, "Oct", 9, "Nov", 10, "Dec", 11);

$mon{"Jan"} = 0;
$mon{"Feb"} = 1;
$mon{"Mar"} = 2;
$mon{"Apr"} = 3;
$mon{"May"} = 4;
$mon{"Jun"} = 5;
$mon{"Jul"} = 6;
$mon{"Aug"} = 7;
$mon{"Sep"} = 8;
$mon{"Oct"} = 9;
$mon{"Nov"} = 10;
$mon{"Dec"} = 11;

This User Gave Thanks to Chubler_XL For This Post:
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