Scripting AIX date output !!

Hi,

I am writing a korn shell script in AIX. I want to pass the date [in YYYYMMDD format] as a parameter to script and inside it should convert the format to +%a" "%h" "%d" "%Y.

For e.g., a parameter passed as "20100301" should be converted to "Mon Mar 01 2010". I can easily do this with AIX "date" option for the current day. Can someone help me to figure out how I can use this script to accept any previous or future dates and return the formatted output as above.

Thanks in advance.

This is easy save for figuring out the day of the week. The rest is simple string manipulation.

You should give perderabo's master hack "datecalc" a try. search for it in our forum, it is a well written shell script and thankfully perderabo has given public permission to use it.

I hope this helps.

bakunin

This could also be done fairly easy with a perl (helper) script (or a C helper).

You only need the seconds since epoch and the built in functions do the rest. This makes printing the date for an offset (such as 1 day from now) really easy... you just add 1 days worth of seconds to the current time, and then print a formatted string.

One key benefit of using the functions (rather than rolling your own) is that they will always get the date right. The pre AIX 6 time database and now the olsen DB in 6.1 always know the proper calculation needs for your TZ such as time shifts, if you have a Feb 29th, etc...