CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Time & Date Math

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

Time & Date Math
PostPosted: Wed Oct 11, 2006 12:05 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 11, 2006 2:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 11, 2006 2:56 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Oct 12, 2006 2:36 am     Reply with quote

In the code library there are some basic Date/Time routines: http://www.ccsinfo.com/forum/viewtopic.php?t=25611
Ttelmah
Guest







PostPosted: Thu Oct 12, 2006 7:17 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group