Hi all,
I am trying to execute the following command in a sun solaris machine and getting the error as below.
bash-2.03$ date -d "1 day ago" +%Y%m%d
date: illegal option -- d
bash-2.03$ uname -a
SunOS gtrd02 5.8 Generic_117350-55 sun4u sparc SUNW,Sun-Fire-V440
Can anybody help me to find an alternate way to calculate yesterday's date with out using the -d option?
---------- Post updated at 10:41 PM ---------- Previous update was at 09:50 PM ----------
got it
YESTERDAY=`TZ=GMT+24 date +%d-%m-%Y`; echo $YESTERDAY
ctsgnb
2
In some other country whose timezone differs from GMT, you should take into account the offset a reliable calculation could be something like
# -- calculate time using GMT --
Uday=`TZ=GMT date +%d` Uhr=`TZ=GMT date +%H` Lday=`date +%d` Lhr=`date +%H`
if [ $Lday = $Uday ]; then
Offset=`expr $Uhr - $Lhr` else Offset=`expr $Uhr + 24 - $Lhr` fi
Diff=`expr 24 + $Offset`
echo -n "yesterday was " TZ=GMT+$Diff date +%Y-%m-%d
Diff=`expr 24 - $Offset`
echo -n "tomorrow will be " TZ=GMT-$Diff date +%Y-%m-%d
1 Like