John <> wrote:
> (Laery) wrote in
> news: om:
>
> > I'm currently adding a new module to an old borland C3.1 application (dos).
> > And I need to calculate a date by subtracting the number of days from
> > a given date.
>
> > I couldn't find one in the help?
>
> Look-up difftime and localtime... They're functions that have been in the
> Borland libraries at least since v1.5 and should help you do what you're
> trying to do.
No, they won't. difftime() gives the difference, in seconds, between two
time_t's; it doesn't allow you to change an existing time_t. localtime()
converts from time_t to struct tm, but doesn't do any other
computations.
Using mktime() is the right solution. If BC3.1 doesn't have it yet
(i.e., if it's pre-ISO), you _may_ be able to get away with subtracting
days*24*3600 from a time_t, but do note that this relies on time_t being
a straight number of seconds since the epoch, which it isn't required to
be. Doing so would make your code unportable, but if it's already
Borland-specific, that may not be a problem. Adding a comment explaining
the hack would be a good idea, even so.
Richard