I am using the following code to find the difference between two dates basically one is current system date and another server date. I am getting different values at different times, hence I changed the format to only include dates and not datetimes. But still the difference of values remains the same issue. Issue as mentioned in the src line comments.
//dtHigher retrieved from a file from Server
COleDateTime datetimetmp = COleDateTime::GetCurrentTime();
CString strhigherDt = dtHigher.Format(_T("%d/%m/%Y")); //12/07/2022
CString strcurrentDt = datetimetmp.Format(_T("%d/%m/%Y")); //07/07/2022
COleDateTime dateHigher, dateCurrent;
dateHigher.ParseDateTime(strhigherDt);
dateHigher.ParseDateTime(strcurrentDt);
COleDateTimeSpan spanDays = dateHigher - dateCurrent;
CString strdatespan = spanDays.Format(_T("%D.%H.%M.%S")); //this gives some times 4.23.59.59, some times 5.00.00.00
int daysRem = (int) ::ceil(spanDays.GetTotalDays()); //based on above return value, its either 4 or 5
CodePudding user response:
Hello I was able to solve it by getting the date, month and year separately from COleDateTime class and getting the difference manually. Thanks for all the help.