"yesterdate" function?
Ken Keirnan
kjk at pbhyf.PacBell.COM
Thu Jan 5 03:43:11 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
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 <time.h>
#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 at pbhyf.PacBell.COM
More information about the Comp.unix.questions
mailing list