"yesterdate" function?

bill vermillion bill at bilver.UUCP
Fri Jan 6 00:51:55 AEST 1989


In article <19100001 at hpficad.HP.COM> mcr at hpficad.HP.COM (Matt Reprogle) writes:
>
>I need a way to get yesterday's date in YYMMDD format in a Unix script and put
>it in a file.   I don't want to write a C program implementing an entire
>calendar to do it. 
>
>Can anyone help?  
>
>Matt Reprogle
>
>{everywhere}!hplabs!hpfcla!mcr

This came by the net awhile back. It might help.

############################################################################
# whenis : find out date relative to today : Andrew Beattie 20/5/87        #
# mcvax!ukc!reading!riddle!andrew                                          #
# andrew at sphinx.co.uk                                                      #
############################################################################
# I place this program in the public domain but please keep this header    #
# on it - I want the fame and glory!                                       #
############################################################################

if [ $# = 0 ]
then
	echo 'whenis today'
	echo 'whenis [next|last|this] sunday|monday|tuesday|wednesday|th...'
	exit
fi

# store current daylight adjustment
light=`echo $TZ | cut -c4`
# find day of week and put '-' in front of it
now=`date '+-%w'`
for i 
do
	case $i in
	today) now=0 ;;
	next) now="$now +7" ;;
	last) now="$now -7" ;;
	tomorrow) now="1" ;;
	yesterday) now="-1" ;;
	sunday) now="$now +0" ;;
	monday) now="$now +1" ;;
	tuesday) now="$now +2" ;;
	wednesday) now="$now +3" ;;
	thursday) now="$now +4" ;;
	friday) now="$now +5" ;;
	saturday) now="$now +6" ;;
	esac
done
# work out number of hours adjustment
adj=`echo "$light + ( -24 * ( $now ) )" |bc`
# now for the magic - adjust the time zone by the given number
# of hours and let date do the hard work.
TZ=GMT$adj date


-- 
Bill Vermillion - UUCP: {uiucuxc,hoptoad,petsd}!peora!rtmvax!bilver!bill
                      : bill at bilver.UUCP



More information about the Comp.unix.questions mailing list