Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!hc!pprg.unm.edu!unmvax!gatech!emory!arnold From: arnold@emory.uucp (Arnold D. Robbins {EUCC}) Newsgroups: comp.unix.questions Subject: Re: "yesterdate" function? Message-ID: <3562@emory.uucp> Date: 4 Jan 89 17:40:13 GMT References: <19100001@hpficad.HP.COM> Reply-To: arnold@emory.UUCP (Arnold D. Robbins {EUCC}) Organization: Emory University Lines: 29 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? This is too hard to pass up. #include #define ONEDAY (24 * 60 * 60) /* seconds in a day */ main () { long yesterday; struct tm* then; (void) time (& yesterday); yesterday -= ONEDAY; then = localtime (& yesterday); (void) printf ("%d%02d%02d\n", then->tm_year, then->tm_mon, then->tm_mday); return 0; } -- "Unix is a Registered | Arnold Robbins -- Emory University Computing Center Bell of AT&T Trademark | DOMAIN: arnold@unix.cc.emory.edu Laboratories." | UUCP: gatech!emory!arnold PHONE: +1 404 727-7636 -- Donn Seeley | BITNET: arnold@emoryu1 FAX: +1 404 727-2599