View previous topic :: View next topic |
Author |
Message |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
Time & Date Math |
Posted: Wed Oct 11, 2006 12:05 pm |
|
|
Hello All,
I'm to a point where I need to do some simple subtractions between two times/dates, to figure out the number of seconds elapsed between two events.
I saw that there is a time.h for C but nothing similar for CCS?
Does anyone know of such an animal? If not, has anyone tackled this already?.... Or am I about to start to do this all myself?
Thanks,
John |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Wed Oct 11, 2006 2:50 pm |
|
|
I don't know of any ready made functions for doing this. I ended up coding it all myself. It isn't too bad to tackle, actually. Just a bit daunting, but once you begin it goes pretty quick. And sorry, I can't share what I have - don't think my customer would appreciate it. |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Wed Oct 11, 2006 2:56 pm |
|
|
OK. Thanks.
I just wanted to make sure that I wasn't going to re-invent the wheel... if there were wheels laying around all over, there were drawings of wheels, and on-line manuals of how make one, etc.
I've got everything done up to here so.... off I go.
John |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
|
Ttelmah Guest
|
|
Posted: Thu Oct 12, 2006 7:17 am |
|
|
The normal way to do this, is to generate a 'date from' value for each date, using some arbitary zero point. These can then be subtracted to give the 'delta days'. Time is relatively easy. Where is gets complex (especially if you need to go back in time), is dealing with DST. The times and amounts used for this, have changed at intervals, making this much harder. If you always use Zulu/UT, this problem is avoided.
The formula commonly used for a 'date from', is:
365*(year-1900) + year/4 - year/100 + year/400 + date + (153*month+8)/5
calculated in integer arithmetic. This fits nicely into 16bit integer arithmetic, giving a day number from 1900, and will still 'fit' in 16bit arithmetic, up to 2084.
Best Wishes |
|
|
|