Path: utzoo!utgpu!attcan!uunet!ssbell!kent From: kent@ssbell.UUCP (Kent Landfield) Newsgroups: comp.unix.questions Subject: Re: "yesterdate" function? Message-ID: <354@ssbell.UUCP> Date: 6 Jan 89 05:00:52 GMT References: <19100001@hpficad.HP.COM> Reply-To: kent@ssbell.UUCP (0000-root) Organization: Sterling Software, FSG-IMD, Bellevue, NE. Lines: 51 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? > I think that the following code will serve your needs. And I didn't need to an entire calendar to do it. ;-) ------------------------- yesterdate.c ---------------------- #include #define SEC_PER_DAY 86400L /* total seconds per day */ main() { long clock, time(); struct tm *yesterday, *localtime(); clock = time((long *) 0); /* get the current time */ /* ** subtract 24 hours worth of seconds from ** the total seconds since the epoch. */ clock -= SEC_PER_DAY; /* ** convert yesterday's second value into a ** tm structure in preparation for output. */ yesterday = localtime(&clock); /* ** print the string containing in the format ** requested YYMMDD and zero padded if single ** digit returned. */ (void) printf("%.2d%.2d%.2d\n", yesterday->tm_year, yesterday->tm_mon + 1, yesterday->tm_mday); return(0); } ---------------------------------------------------- Kent Landfield Phone: (402) 291-8300 Sterling Software FSG/IMD UUCP: kent@ssbell 1404 Ft. Crook Rd. South INTERNET: kent%ssbell.uucp@uunet.uu.net Bellevue, NE. 68005-2969 FAX: (402) 291-4362