It is narrated from Sayyiduna Abdullah bin Umar (may Allah be pleased with them both) that the Messenger of Allah (peace and blessings be upon him) besieged Ta'if for seventeen days, and he (peace and blessings be upon him) kept praying two rak'ahs each.
The Shaykh said: Whoever counts the stay as nineteen days makes it nineteen by including both the day of entering Makkah and the day of leaving.
Whoever counts the stay as 18 days counts one of the two days of arrival and departure, and whoever counts the stay as 17 days does not count either of those two days.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 5472