Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot use GetDate by PHV on AIX

Status
Not open for further replies.
Apr 28, 2003
122
US
I cannot determine why this script How do I get any date relative to today (in ksh) by PHV to work on AIX. I think it may be how 5.2 returns $TZ but I am lost on how to debug this. Can someone lend some expertise?

Here is $TZ in ksh on my machine:
EST5EDT,M3.2.0/2:00:00,M11.1.0/2:00:00

Thanks in Advance,

[morning] needcoffee
 
Did you read PHV's note?

PHV said:
#-- Note:
On some *nix flavor the authorized displacement is limited to +/-168 hours and thus the above "Next week" test fails.

I think AIX is one of those "limited" *nixes.


HTH,

p5wizard
 
p5wizard,

The max change I am using this for is 6 days so I am below this threshold. Do you have any suggestions on an alternative way to do this?

Thanks,

[morning] needcoffee
 
I've used a similar function on AIX to get yesterday's (or tomorrow's ?) date on AIX, but I'm not at a machine right now. I'll see if I can dig it up tomorrow.


HTH,

p5wizard
 
PHV's code looks OK to me...

[tt]$ cat getd
GetDate(){ # GetDate nDays [format]
typeset -i nDays=$1; format=$2
eval $(echo $TZ | sed '
s!\([^-0-9]*\)\([-0-9]*\)\(.*\)!typeset -i localOffset=\2;zon1=\1;zon2=\3!')
TZ=$zon1$((localOffset-24*nDays))$zon2 date $format
}

echo "Yesterday: $(GetDate -1)"
echo "Tomorrow: $(GetDate 1)"
echo "Next week: $(GetDate 7 '+%Y-%m-%d')"
$ # on my timezone:
$ echo $TZ
CET-1CDT,M3.5.0/02:00,M10.5.0/03:00
$ ./getd
Yesterday: Wed Apr 16 08:51:26 CDT 2008
Tomorrow: Fri Apr 18 08:51:26 CDT 2008
Next week: 2008-04-24
$ # on yours:
$ TZ=EST5EDT,M3.2.0/2:00:00,M11.1.0/2:00:00
$ ./getd
Yesterday: Wed Apr 16 02:51:33 EDT 2008
Tomorrow: Fri Apr 18 02:51:33 EDT 2008
Next week: 2008-04-24[/tt]


HTH,

p5wizard
 
OK,

Got it working. I am officially a moron this week due to sleep deprivation. I forgot to call the funtion again within the script I put this into.

My apologies all,

[morning] needcoffee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top