You could use a better approximation of the number of days in a month. The Gregorian calendar averages to 365.2425 days per year, so an average month is 30.4369 days. For many purposes this is close enough.
If it is for payroll purposes you are better going the long way with something like:
int wholeMonths
(const QDate &from,
const QDate &to
) {
if (from.isValid() && to.isValid() && to > from) {
int months = qMax(1, (to.year() - from.year() - 1) * 12);
while (from.addMonths(months) <= to)
++months;
return months - 1;
}
else
return 0;
}
int wholeMonths(const QDate &from, const QDate &to)
{
if (from.isValid() && to.isValid() && to > from) {
int months = qMax(1, (to.year() - from.year() - 1) * 12);
while (from.addMonths(months) <= to)
++months;
return months - 1;
}
else
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks