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

How do you subtract two dates and times from each other?

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



Joined: 12 May 2007
Posts: 1

View user's profile Send private message

How do you subtract two dates and times from each other?
PostPosted: Tue Dec 06, 2011 2:35 pm     Reply with quote

Hi Everyone,

Can anyone suggest an approach on how to subtract one time and date from another later time and date? I have an RTC that gives me the current year, month, day, hour, min and sec. I want to find the delta in seconds between this current time and an earlier time and date. Leap years are also a consideration. I looked at using look up tables for months, etc, but it got messy. I don't need the code, just the best way to handle this. I have plenty of ROM and a good amount of RAM so that will not be an issue.

Thanks!
_________________
Jim T.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Dec 06, 2011 2:51 pm     Reply with quote

BTDTGTTS
one way:

1- convert the dates to seconds as 32bit unsigned int
( taking in to account leap years etc)

2- subtract lesser from greater

thats the diff in time

need more accuracy ? use msecs
Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 06, 2011 3:01 pm     Reply with quote

Here is a previous thread on the topic:
http://www.ccsinfo.com/forum/viewtopic.php?t=43113
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