Valhalla Legends Forums Archive | C/C++ Programming | the best way to do this...

AuthorMessageTime
treyreese
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?
February 5, 2004, 8:20 PM
Yoni
Try: difftime
February 5, 2004, 8:49 PM
treyreese
difftime is used for days or seconds and stuff?
February 5, 2004, 8:53 PM
Yoni
Yes, you got it! Enjoy.
February 5, 2004, 9:05 PM
Adron
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.
February 5, 2004, 11:23 PM
treyreese
heh im confused with it, i have never really used time.h so i don't understand it
February 6, 2004, 3:29 AM
iago
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 for more information.
February 6, 2004, 12:55 PM
Kp
[quote author=iago link=board=30;threadid=5096;start=0#msg42769 date=1076072153]
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 for more information.
[/quote]

time_t is in seconds, not milliseconds.
February 6, 2004, 9:34 PM
iago
[quote author=Kp link=board=30;threadid=5096;start=0#msg42834 date=1076103291]
[quote author=iago link=board=30;threadid=5096;start=0#msg42769 date=1076072153]
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 for more information.
[/quote]

time_t is in seconds, not milliseconds.
[/quote]

Well, there's some time structure that's in milliseconds! :)

I've been using java.util.Time.getCurrentTimeInMillis() to much, I guess!
February 6, 2004, 9:46 PM
Skywing
[quote author=iago link=board=30;threadid=5096;start=0#msg42838 date=1076104004]
[quote author=Kp link=board=30;threadid=5096;start=0#msg42834 date=1076103291]
[quote author=iago link=board=30;threadid=5096;start=0#msg42769 date=1076072153]
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 for more information.
[/quote]

time_t is in seconds, not milliseconds.
[/quote]

Well, there's some time structure that's in milliseconds! :)

I've been using java.util.Time.getCurrentTimeInMillis() to much, I guess!
[/quote]
There is no C standard structure like that.
February 10, 2004, 5:34 PM
Adron
[quote author=Skywing link=board=30;threadid=5096;start=0#msg43519 date=1076434446]

There is no C standard structure like that.
[/quote]

The closest common C structure I can think of is timeval with microseconds.
February 10, 2004, 6:03 PM
Skywing
[quote author=Adron link=board=30;threadid=5096;start=0#msg43529 date=1076436189]
[quote author=Skywing link=board=30;threadid=5096;start=0#msg43519 date=1076434446]

There is no C standard structure like that.
[/quote]

The closest common C structure I can think of is timeval with microseconds.
[/quote]
That is POSIX and not C standard, though.
February 10, 2004, 6:04 PM
Adron
[quote author=Skywing link=board=30;threadid=5096;start=0#msg43532 date=1076436285]
That is POSIX and not C standard, though.
[/quote]

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?
February 10, 2004, 6:16 PM

Search