I'm trying to make a program where the user inputs the startmonth/startday and the endmonth/endday in the format like 1/1 2/1. What would be the best way to figure out how many days is inbetween the two dates?
Try: difftime
difftime is used for days or seconds and stuff?
Yes, you got it! Enjoy.
I tend to turn times into time_t's internally since those are easy to use. Subtracting two time_t's to find a difference in days, hours, whatever, is easy.
heh im confused with it, i have never really used time.h so i don't understand it
Basically, convert both dates to the number of milliseconds since some arbitrary date, subtract them, and turn them back. Look up time_t on Google (http://www.google.ca/search?q=time_t) for more information.
Quote from: iago on February 06, 2004, 06:55 AM
Basically, convert both dates to the number of milliseconds since some arbitrary date, subtract them, and turn them back. Look up time_t on Google (http://www.google.ca/search?q=time_t) for more information.
time_t is in seconds, not milliseconds.
Quote from: Kp on February 06, 2004, 03:34 PM
Quote from: iago on February 06, 2004, 06:55 AM
Basically, convert both dates to the number of milliseconds since some arbitrary date, subtract them, and turn them back. Look up time_t on Google (http://www.google.ca/search?q=time_t) for more information.
time_t is in seconds, not milliseconds.
Well, there's some time structure that's in milliseconds! :)
I've been using java.util.Time.getCurrentTimeInMillis() to much, I guess!
Quote from: iago on February 06, 2004, 03:46 PM
Quote from: Kp on February 06, 2004, 03:34 PM
Quote from: iago on February 06, 2004, 06:55 AM
Basically, convert both dates to the number of milliseconds since some arbitrary date, subtract them, and turn them back. Look up time_t on Google (http://www.google.ca/search?q=time_t) for more information.
time_t is in seconds, not milliseconds.
Well, there's some time structure that's in milliseconds! :)
I've been using java.util.Time.getCurrentTimeInMillis() to much, I guess!
There is no C standard structure like that.
Quote from: Skywing on February 10, 2004, 11:34 AM
There is no C standard structure like that.
The closest common C structure I can think of is timeval with microseconds.
Quote from: Adron on February 10, 2004, 12:03 PM
Quote from: Skywing on February 10, 2004, 11:34 AM
There is no C standard structure like that.
The closest common C structure I can think of is timeval with microseconds.
That is POSIX and not C standard, though.
Quote from: Skywing on February 10, 2004, 12:04 PM
That is POSIX and not C standard, though.
That's why I said a common C structure. Most of the C compilers support POSIX, in some form, some parts of it. Can you think of any other common time structure with more than second accuracy?