Returns the previous month of a date entered in Qt

4

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.

    
asked by anonymous 06.04.2015 / 17:46

1 answer

4

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);
    
06.04.2015 / 17:53