[H-GEN] time in C/C++
Frank Brand
fbrand at uq.net.au
Tue Dec 28 04:59:15 EST 1999
[ Humbug *General* list - semi-serious discussions about Humbug and ]
[ Unix-related topics. Please observe the list's charter. ]
On Mon, 27 Dec 1999, Andrae Muys wrote:
> [ Humbug *General* list - semi-serious discussions about Humbug and ]
> [ Unix-related topics. Please observe the list's charter. ]
>
> On Sun, 26 Dec 1999, Frank Brand wrote:
>
> >
> > My query is to asak what people think about the best way of getting the time
> > between dates. Originally, I thought to use difftime() but I believe that this
> > method can lead to errors under some circumstances.
> >
>
> How are you storing the dates interanally? If you're using time_t's then
> a simple difference should be sufficient, otherwise my gut feeling is to
> convert to time_t do the calculation and convert to days /3600.0 iirc.
The divisor is 86,400 if you want to convert to days - time_t results
in seconds and there are 86,400 in a day.
Isn't this what difftime() does ? (time_t 2 - time_t 1) ?
I suppose what I was really querying is whether there are any errors that can
result from using time_t / difftime(). I recall reading a text that said that
there may be some inaccuracies in UNIX and it would be better to write your own
function (don't exactly know why but that is what was said). Maybe it was Bill
Gates guide to smarter programming? In any case, so long as errors do not
extend to a day it would be OK as the programme needs to apportion coupon
payments (interest) over a period based on days - so many days interest goes to
customer 1 and the rest goes to customer 2.
At this stage I am not storing "dates", simply numbers in fields. I anticipated
writing a function so just needed day, month and year as individual numbers
that I could use to do the day additions/ leap year checks etc etc. Depending
on how I finally decide to set it up I can change the input to suit - I am
still playing with the final design/appearance.
--
Frank Brand
E-mail: fbrand at uq.net.au
Home Page: http://www.uq.net.au/~zzfbrand
--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.
More information about the General
mailing list