[SunHELP] Solaris10 date calculation not working?

D R Hughes enquiries at bswpc.co.uk
Tue Oct 13 15:06:59 CDT 2009


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`
> 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



More information about the SunHELP mailing list