How do I return the previous month of the date reported in Qt, does it have any function in QDate
that does this? I found only the one that adds addMonths
. Example: Month 04 reported returns month 03.
How do I return the previous month of the date reported in Qt, does it have any function in QDate
that does this? I found only the one that adds addMonths
. Example: Month 04 reported returns month 03.
Yes, the month()
method does this.
QDate data(2015, 4, 6);
int mes = data.month();
According to the comment below, what is desired is to subtract months, so use the addMonths()
, just use a negative value.
QDate data(2015, 4, 6);
int mesAnterior = data.addMonths(-1);