0

I'd like to write a function in C that takes the current system date adds a user defined number of days and returns the new date. Im new to C so Id like any suggestions . Thanks in Advance.

4
Contributors
5
Replies
7
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

Ive been looking at time.h, still need to see some code to do that. Ive searched the web but found little help. Thanks.

0

What have you found out? What format is the system time if you need to add to it? What function(s) do you need to call?

0

1. get current time in the form of struct tm (two function calls to do that)

2. Get number of days from user

3. Add days from #2 above to tm_mday obtains in #1 above

4. call mktime() to normalize all struct tm members.

Note: you can't do silly things like advance number of days beyone the limits of time_t or subtract them to that the result is before 1 Jan 1970. If you want to do that then you will have to use something else, such as write your own function to handle such times.

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.