How to get previous day from UNIX AIX?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get previous day from UNIX AIX?
# 1  
Old 03-21-2017
How to get previous day from UNIX AIX?

Does anybody know how to get previous day on UNIX AIX?

I tried
Code:
TZ=XYZ+24 date '+%y%m%d'

But it doesn't understand

Thanks for contribution
# 2  
Old 03-21-2017
Hello digioleg54,

If you have GNU date in your system then following may help you in same.
Code:
 date -d"1 day ago"

Thanks,
R. Singh
# 3  
Old 03-21-2017
No, our system is very old. we don't have GNU
# 4  
Old 03-21-2017
Just in case you missed it: we a have a special AIX-forum dedicated to the best UNIX-OS of them all. ;-))
Quote:
Originally Posted by digioleg54
No, our system is very old. we don't have GNU
In fact your system is not necessarily old but simply POSIX - AIx uses POSIX-compliant utilities and the POSIX-date doesn't have the -d flag.

You can do the following: (every) UNIX, including AIX, maintains the time as a (permanently updated) 32-bit (64-bit?) integer, which is counting the seconds since 0:00 Jan 1st 1970. "Time" is generally maintained in CUT (coordinated universal time, basically GMT) systemwide, from this the "TZ"-string is "added". You can modify the TS-string which contains an offset to the system time, for a single command like this:

Code:
# echo $TZ
GMT-1
# date ; TZ=GMT+23 date
Tue Mar 21 14:35:15 CET 2017
Mon Mar 20 14:35:15 GMT 2017

You can, the same way, subtract or add arbitrary values by adding/subtracting multiples of 24 from/to the TZ-offset:

Code:
# date ; TZ=GMT+23 date ; TZ=GMT+47 date
Tue Mar 21 14:37:39 CET 2017
Mon Mar 20 14:37:39 GMT 2017
Sun Mar 19 14:37:39  2017
# date ; TZ=GMT-25 date ; TZ=GMT-49 date
Tue Mar 21 14:38:57 CET 2017
Wed Mar 22 14:38:57 GMT 2017
Thu Mar 23 14:38:57 GMT 2017

Apply necessary format codes normally to the date-command.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 5  
Old 03-21-2017
Code:
# usage then.pl 7 for date seven days ago
ago()
{
   perl -e ' my $delta = $ARGV[0];
             $delta*=86400;
             $delta=time - $delta;
             @t=localtime( $delta );
             printf("%02d-%02d-%d", $t[4]+1, $t[3], $t[5]+1900); ' $1
}

echo $(ago $1)

For yesterday:

Code:
 ./then.pl 1

to change the date format rearrange the printf statement. t is an array see examples here:

localtime - perldoc.perl.org
# 6  
Old 03-21-2017
Code:
perl -e 'printf "%s\n",scalar localtime(time-86400)'
perl -MPOSIX -e 'print POSIX::strftime("%Y%m%d%H%M\n", localtime(time-86400));'

I believe you can also do this on AIX - don't have AIX to validate:
Code:
echo $(echo '*time-0t86400=Y' | /usr/bin/adb -k | tail -2)

# 7  
Old 03-22-2017
I'm not sure you need the + on your original command. I wrote a whole pile of things to exploit the fact that AIX recognises huge TZ offsets to work out what days we had to reports against and what days we had to write projections for (i.e. direct-debit due dates etc.)

I think it is just:-
Code:
# Save current TZ first
orig_TZ=$TZ

TZ=GMT24BST         # as appropriate
date '+%Y %m %d'    # grab this somehow

TZ=GMT72BST         # 3 days ago
date '+%Y %m %d'    # grab this somehow

TZ=GMT-48BST        # 2 days future
date '+%Y %m %d'    # grab this somehow

# Reset to original TZ
TZ=orig_TZ

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

AIX UNIX - script on how to extract from log file with previous date

Hello, I am new to this forum so any assistance would help. I am currently trying to develop a script that extract all data from a log file with has the previous day's date. $ <root@aixtest3> /var/log > more sudo.log May 13 10:52:10 aixtest3 local2:notice sudo: tbrath : TTY=unknown ; ... (14 Replies)
Discussion started by: Kslew82
14 Replies

2. Shell Programming and Scripting

Get Previous day error from alertlog

Hi All, I want to get the all ORA- related errors from attached logfile for previous day. Pls help. Thanks ! Regards Kamal (7 Replies)
Discussion started by: kamauv234
7 Replies

3. UNIX for Dummies Questions & Answers

Move the files between Current day & a previous day

Hi All, I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day. i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.... (2 Replies)
Discussion started by: dsfreddie
2 Replies

4. Shell Programming and Scripting

Script to check if last modified day is previous day

Hi, I would like to write a script that checks if a file ('counter') was modified the previous day, if so erase its contents and write 00000000 into it. For e.g. if the file 'counter' was last modified at 11.30pm on 24th May and the script runs at 12.15am of 25th May, it should erase it's... (1 Reply)
Discussion started by: hegdepras
1 Replies

5. Shell Programming and Scripting

getting previous day.

Hi, i am developing a script for my project. In my script i need to check some conditions based upon some values. in that one value is the previous date. with the previous date i need to check and process some values. I have a function with me retrieve the yesterdays date. But now i have a... (6 Replies)
Discussion started by: intiraju
6 Replies

6. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

7. Shell Programming and Scripting

Display month for Previous day

Hello - I have one question regarding the date. I wanted to display the month name for previous day. The output should be as follows... 5-Feb-09 => February 1-Feb-09 => January 28-Feb-09=> February Here is the code i am using to get the output.... date '+%m %d %Y' | { read MONTH DAY... (4 Replies)
Discussion started by: govindts
4 Replies

8. Shell Programming and Scripting

next/Previous business day

Hello, Can you please help me how do i get previous and next working day of the week for a given date excluding saturday and sunday. Ex: if the given date is monday, i should get friday and tuesday's date if the given date is friday, i should get thrusday and monday's date. Thanks,... (4 Replies)
Discussion started by: kotasateesh
4 Replies

9. Shell Programming and Scripting

How to find the first day of previous month in unix?

How to find the first day of previous month in unix mmddyyyy format? example : today is 07052007 (in mmddyyyy) output sud be 06012007 thanks mohapatra (10 Replies)
Discussion started by: mohapatra
10 Replies

10. Shell Programming and Scripting

Previous day's date in Perl?

Hi All, I want to find the previous day's date and store that in a variable, which will be usuful for further processing. Any help please. Regards, raju (4 Replies)
Discussion started by: rajus19
4 Replies
Login or Register to Ask a Question