Return to BSD News archive
Xref: sserve comp.unix.bsd:14579 comp.unix.misc:13498 comp.unix.programmer:19254 comp.unix.questions:53640
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msuinfo!agate!howland.reston.ans.net!gatech!taco.cc.ncsu.edu!shaman.cc.ncsu.edu!rcb
From: rcb@shaman.cc.ncsu.edu (Randy Buckland)
Newsgroups: comp.unix.bsd,comp.unix.misc,comp.unix.programmer,comp.unix.questions
Subject: Re: Q: How can I get yesterday's date?
Date: 16 Aug 1994 13:28:22 GMT
Organization: North Carolina State University
Lines: 42
Message-ID: <32qetm$cq7@taco.cc.ncsu.edu>
References: <Pine.3.89.9408160216.A15886-0100000@worf.uwsp.edu>
NNTP-Posting-Host: shaman.cc.ncsu.edu
X-Newsreader: NN version 6.5.0 #4 (NOV)
pzuge@worf.uwsp.edu (Peter Zuge) writes:
>I need to create a script that will run at a certain time everyday
>"getting" ( via ftp ) a file with yesterday's date.
>I have the script working except for one detail; "getting" the file using
>the actual name. The name of the file uses the date for its name
>( format: GS940815.LOG or "GS" + yy + mm + dd + ".LOG" ).
>Question: How can I get the date just previous to today, and put it into
> the correct format I need?
Try this:
------------------swdate.c-----------------------------
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
main(int argc, char *argv[])
{
int day_offset;
int currtime;
struct tm *timbuf;
if (argc != 2) {
fprintf (stderr, "Usage: swdate delta_days\n");
exit(1);
}
day_offset = atoi(argv[1]);
time(&currtime);
currtime += (day_offset*60*60*24);
timbuf = localtime (&currtime);
printf ("%02d-%02d-%02d\n", timbuf->tm_mon+1, timbuf->tm_mday,
timbuf->tm_year);
}
--
Randy Buckland "It's hard to work
North Carolina State University in a group when you're
randy_buckland@ncsu.edu (919) 515-5491 omnipotent" -- Q