• Welcome to Valhalla Legends Archive.
 

the best way to do this...

Started by treyreese, February 05, 2004, 02:20 PM

Previous topic - Next topic

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?

Yoni


treyreese

#2
difftime is used for days or seconds and stuff?

Yoni


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.

treyreese

heh im confused with it, i have never really used time.h so i don't understand it

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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Kp

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 for more information.

time_t is in seconds, not milliseconds.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

iago

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 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!
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Skywing

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 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.

Adron

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.

Skywing

#11
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.

Adron

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?