Calculate Date Difference in months
-
Hi All, I am writing one function that should return me a difference between given dates in months. I know it can easily be done by getting difference in years, months and days. Then calculate months like trmMonths = 0; trmMonths += years * 12; trmMonths += months; But i am not sure about what to do with days, because sometimes it may happen that difference between dates would be years = 1 months = 11 days = 28. in this case the difference between dates should be 24months. Can anyone give me idea on how days can be handled here to get accurate difference? Thanks, AksharRoop
-
Hi All, I am writing one function that should return me a difference between given dates in months. I know it can easily be done by getting difference in years, months and days. Then calculate months like trmMonths = 0; trmMonths += years * 12; trmMonths += months; But i am not sure about what to do with days, because sometimes it may happen that difference between dates would be years = 1 months = 11 days = 28. in this case the difference between dates should be 24months. Can anyone give me idea on how days can be handled here to get accurate difference? Thanks, AksharRoop
AksharRoop wrote:
But i am not sure about what to do with days, because sometimes it may happen that difference between dates would be years = 1 months = 11 days = 28. in this case the difference between dates should be 24months.
:confused: Err I'm totally confused by your sentence here. Could you explain a bit better what is the problem exactly ? Are you using COleDateTime and/or COleDateTimeSpan classes ? This could help you manipulating times.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++