LinuxQuestions.org

LinuxQuestions.org (http://www.linuxquestions.org/questions/index.php)
-   AIX (http://www.linuxquestions.org/questions/forumdisplay.php?f=43)
-   -   shell script for date (http://www.linuxquestions.org/questions/showthread.php?t=4175447005)

rajachan 01-24-2013 03:56 AM

shell script for date
 
hi

how to do a shell script in aix to display 15 day before the current date.

linosaurusroot 01-24-2013 05:17 AM

perl -e 'print scalar localtime (time - (15 * 86400))'

shivaa 01-26-2013 12:44 AM

Not much sure about AIX, but can you try like bash style:
Code:

PREVDATE=$(date --date="15 day ago")
echo $PREVDATE


David the H. 01-27-2013 02:48 PM

AIX's version of date doesn't have -d, so that won't work.

A quick google turned up this date script. I don't know how well it works:
http://www.williamrobertson.pwp.blue...shift_date.txt

rajachan 01-28-2013 01:30 AM

thanks linosaurusroot

your command is working

i am getting the result in following format...

sun jan 13 hh:mm::sec 2013

is it possible to display the date in below format..

13-jan-13

linosaurusroot 01-28-2013 04:13 AM

"perldoc localtime" shows the breakdown.

NevemTeve 01-28-2013 09:03 AM

you might want to install GNU-date, perhaps by name gdate so you could use this way:

Code:

gdate -d'15 days ago' +%d-%b-%y

David the H. 01-31-2013 01:15 PM

You could also use nawk or gawk if you have them (posix awk/mawk don't have time functions).

Code:

nawk 'BEGIN{ print strftime( "%d-%b-%y" , systime() - 15 * 86400 ) }'


All times are GMT -5. The time now is 12:27 AM.