View previous topic :: View next topic |
Author |
Message |
JimT1959
Joined: 12 May 2007 Posts: 1
|
How do you subtract two dates and times from each other? |
Posted: Tue Dec 06, 2011 2:35 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Dec 06, 2011 2:51 pm |
|
|
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](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
|