stephen price | 12 Oct 2009 04:08
Picon
Favicon

Solaris10 date calculation not working?

I'm trying to do a simple "what date is yesterday" shell script variable - without having to go to perl or
something else.

# todays date & time
d1=`date +%Y%m%d%H%M`
echo $d1
#yesterdays date & time - should be 24 hours back
yesterday1=`TZ=US/Central+24 date +%Y%m%d%H%M`
yesterday2=`TZ=CST6CDT+24 date +%Y%m%d%H%M`
yesterday3=`TZ=America/Chicago+24 date +%Y%m%d%H%M`
echo
echo $yesterday1
echo $yesterday2
echo $yesterday3

200910111937

200910110037
200910110037
200910110037

Why is it only 19 hours back instead of the 24 hours ?
I tried ksh & sh & bash - just in case korn wasn't handling correctly - but still got the same output.
I'm sure I'm missing something simple - 
Any suggestions welcome ...

steve
_______________________________________________
SunHELP maillist  -  SunHELP <at> sunhelp.org
http://www.sunhelp.org/mailman/listinfo/sunhelp
(Continue reading)

Sandwich Maker | 12 Oct 2009 05:35
Picon

Re: Solaris10 date calculation not working?

" From: stephen price <sd_price <at> yahoo.com>
" 
" I'm trying to do a simple "what date is yesterday" shell script variable - without having to go to perl or
something else.
" 
" []
" yesterday2=`TZ=CST6CDT+24 date +%Y%m%d%H%M`
" 
" []
" 
" Why is it only 19 hours back instead of the 24 hours ?

try adding the 24 to the 6 algebraically instead of string concat, eg.
TZ=CST30CDT date

" I tried ksh & sh & bash - just in case korn wasn't handling correctly - but still got the same output.
" I'm sure I'm missing something simple - 
" Any suggestions welcome ...

i've been doing the above since 2.4.  in fact, i've used some rather
large numbers for the tz offset...

how about
typeset -i NODAYS=0	# no. of days into past, init none.
.
.
# set NODAYS
.
.
TZ=CST$((6+(24*NODAYS)))CDT
(Continue reading)

D R Hughes | 13 Oct 2009 22:06
Picon

Re: Solaris10 date calculation not working?

Don't know if its any use, but the following seems to work with bash:-

bash-3.00$ yd1=`TZ=CST6CDT+$[24+6] date +%Y%m%d%H%M`
bash-3.00$ echo $yd1

or just;

bash-3.00$ yd1=`TZ=CST+$[24+6] date +%Y%m%d%H%M`
bash-3.00$ echo $yd1

The bourne (sh) shell:-

$ sum=`expr 24 - 6`
$ yesterdaydate=`TZ=CST+$sum date +%Y%m%d%H%M`
$ echo $yesterdaydate

Hope these are useful.

Rhys

stephen price wrote:
> I'm trying to do a simple "what date is yesterday" shell script variable - without having to go to perl or
something else.
>
> # todays date & time
> d1=`date +%Y%m%d%H%M`
> echo $d1
> #yesterdays date & time - should be 24 hours back
> yesterday1=`TZ=US/Central+24 date +%Y%m%d%H%M`
> yesterday2=`TZ=CST6CDT+24 date +%Y%m%d%H%M`
(Continue reading)


Gmane