Get dates between two end dates
Solved
General and Desktop
-
HI,
I have been working on a program which will display all the dates between a Start date and an End date.
So far, I haven't been able to come up with logic or find solution. We can use daysto(QDate) to get number of days for other date that's clear.
can someone help me with this?
Thanks in Advance. -
I fail to see the difficulty, what did you try so far ?
int main(int argc, char *argv[]) { QApplication a(argc, argv); QDate d1 = QDate::currentDate(); QDate d2 = d1.addYears(1); QVector<QDate> dateList; for(int i(0); i <d1.daysTo(d2); i++) dateList.append(d1.addDays(i)); for(const QDate & d: dateList) qDebug() << d; return a.exec(); }
-
@J-Hilk said in Get dates between two end dates:
for(const QDate & d: dateList)
Ehem... better use:
for (const QDate &d : qAsConst(dateList))
as range for on non-const Qt container might be expensive.
Btw:
for(int i(0); i <d1.daysTo(d2); i++)
: it might be better to calculated1.daysTo(d2)
outside the comparison once.Regards