Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!pacbell!pbhyf!kjk From: kjk@pbhyf.PacBell.COM (Ken Keirnan) Newsgroups: comp.unix.questions Subject: Re: "yesterdate" function? Message-ID: <4479@pbhyf.PacBell.COM> Date: 4 Jan 89 17:43:11 GMT References: <19100001@hpficad.HP.COM> Reply-To: kjk@pbhyf.PacBell.COM (Ken Keirnan) Organization: Pacific * Bell, San Ramon, CA Lines: 47 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 If you are using System V, this little program will do what you want. If you are using BSD (or some other variant :-)) you are on your own. -------- CUT HERE -------- CUT HERE -------- CUT HERE -------- CUT HERE /* * Print yesterdays date in format YYMMDD */ #include #define ONEDAY 86400L /* seconds in a day */ main() { register struct tm *tp; long t, time(); t = time((long *)0) - ONEDAY; tp = localtime(&t); printf("%.2d%.2d%.2d\n", tp->tm_year, tp->tm_mon+1, tp->tm_mday); return(0); } -------- CUT HERE -------- CUT HERE -------- CUT HERE -------- CUT HERE Ken Keirnan -- Ken Keirnan - Pacific Bell - {att,bellcore,sun,ames,pyramid}!pacbell!pbhyf!kjk San Ramon, California kjk@pbhyf.PacBell.COM