Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: treyreese on February 05, 2004, 02:20 PM

Title: the best way to do this...
Post by: treyreese on February 05, 2004, 02:20 PM
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?
Title: Re:the best way to do this...
Post by: Yoni on February 05, 2004, 02:49 PM
Try: difftime
Title: Re:the best way to do this...
Post by: treyreese on February 05, 2004, 02:53 PM
difftime is used for days or seconds and stuff?
Title: Re:the best way to do this...
Post by: Yoni on February 05, 2004, 03:05 PM
Yes, you got it! Enjoy.
Title: Re:the best way to do this...
Post by: Adron on February 05, 2004, 05:23 PM
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.
Title: Re:the best way to do this...
Post by: treyreese on February 05, 2004, 09:29 PM
heh im confused with it, i have never really used time.h so i don't understand it
Title: Re:the best way to do this...
Post by: 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.
Title: Re:the best way to do this...
Post by: 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.
Title: Re:the best way to do this...
Post by: 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!
Title: Re:the best way to do this...
Post by: Skywing on February 10, 2004, 11:34 AM
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.
Title: Re:the best way to do this...
Post by: 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.
Title: Re:the best way to do this...
Post by: Skywing on February 10, 2004, 12:04 PM
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.
Title: Re:the best way to do this...
Post by: Adron on February 10, 2004, 12:16 PM
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?