Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!fernwood!uupsi!sunic!sics.se!fuug!news.funet.fi!hydra!klaava!wirzeniu From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius) Newsgroups: comp.lang.c Subject: Re: Time Info Summary: Use difftime, oops, don't have it, try 'now - then' instead. Keywords: time accounting Message-ID: <1991May26.084809.4636@klaava.Helsinki.FI> Date: 26 May 91 08:48:09 GMT References: <39@neis.UUCP> Organization: University of Helsinki Lines: 44 In article <39@neis.UUCP> molnar@neis.UUCP (Christopher Molnar) writes: >I am writing a C routine that needs to compare a start time and >the current time and have the result in minute. > >Can any-one suggest where to find this in the Xenix reffereance manuals >or suggest a way I can accomplish this? The standard library function difftime returns the difference in seconds between two times (represented as time_t's, i.e. whatever time() returns). This is easy to convert to minutes: time_t then, now; double secs, mins; /* difftime returns * double */ time(&then); ..... time(&now); secs = difftime(then, now); mins = secs / 60.0; /* you could do some * rounding here, if you * prefer */ Oops. I just checked my manuals for Xenix, and it seems that it doesn't have difftime. :-( In that case one needs to take advantage of the fact that time_t on SCO Xenix (and most of the Unix world) is a long that tells the seconds since the beginning of the Era (January 1, 1970, at 00:00:00 GMT), so the difftime can be replaced by secs = (double) (now - then); /* of course, you could * use long for secs now, * but that would make it * more difficult to use * difftime in the future. */ and the rest is identical. -- Lars Wirzenius wirzeniu@cc.helsinki.fi