How can get total months ?
-
Hi all, i have two COleDateTime type variable, i want to calculate between them in terms of months. i mean i want to calculate total months between them. i m checking COleDateTimeSpan but there is no function for GetTotalMonths please tell me how can i do this. thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
-
Hi all, i have two COleDateTime type variable, i want to calculate between them in terms of months. i mean i want to calculate total months between them. i m checking COleDateTimeSpan but there is no function for GetTotalMonths please tell me how can i do this. thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
You can use GetDays () function of COleDateTimeSpan class. If you divide Days by 30, you will get the approximate months. The other option is to use int GetMonth() function of COleDateTime variables. This will return the month value in int. If you subtract the values, you can get the approximate month difference. (But you have to take care of the year also).
-
You can use GetDays () function of COleDateTimeSpan class. If you divide Days by 30, you will get the approximate months. The other option is to use int GetMonth() function of COleDateTime variables. This will return the month value in int. If you subtract the values, you can get the approximate month difference. (But you have to take care of the year also).
-
Hi all, i have two COleDateTime type variable, i want to calculate between them in terms of months. i mean i want to calculate total months between them. i m checking COleDateTimeSpan but there is no function for GetTotalMonths please tell me how can i do this. thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
COleDateTime has GetMonth, GetDay and GetYear methods that would allow you to determine the difference in real, calendar months:
int GetMonthsBetween(COleDateTime a, COleDateTime b) { if (a < b) return GetMonthsBetween(b, a); const int aMonths = a.GetYear()*12 + a.GetMonth(); const int bMonths = b.GetYear()*12 + b.GetMonth(); const bool needToRoundDown = (aMonths>bMonths) && (a.GetDay() < b.GetDay()); return (aMonths - bMonths) - ( needToRoundDown? 1 : 0 ); }
This will round the month count down if necessary. For example, consider if a = June 12th and b = May 25th - you can see there's less than one full month between them. -
COleDateTime has GetMonth, GetDay and GetYear methods that would allow you to determine the difference in real, calendar months:
int GetMonthsBetween(COleDateTime a, COleDateTime b) { if (a < b) return GetMonthsBetween(b, a); const int aMonths = a.GetYear()*12 + a.GetMonth(); const int bMonths = b.GetYear()*12 + b.GetMonth(); const bool needToRoundDown = (aMonths>bMonths) && (a.GetDay() < b.GetDay()); return (aMonths - bMonths) - ( needToRoundDown? 1 : 0 ); }
This will round the month count down if necessary. For example, consider if a = June 12th and b = May 25th - you can see there's less than one full month between them.