Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-ncis!helios.ee.lbl.gov!pasteur!ames!pacbell!hoptoad!peora!rtmvax!bilver!bill From: bill@bilver.UUCP (bill vermillion) Newsgroups: comp.unix.questions Subject: Re: "yesterdate" function? Message-ID: <353@bilver.UUCP> Date: 5 Jan 89 14:51:55 GMT References: <19100001@hpficad.HP.COM> Reply-To: bill@bilver.UUCP (bill vermillion) Organization: W. J. Vermillion, Winter Park, FL Lines: 61 In article <19100001@hpficad.HP.COM> mcr@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@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@bilver.UUCP