For how long does the treatment for UTI last.

Varies. Depending upon the site of the UTI and the causative agent it may be as little as a day, or in the case of pyelonephritis, may be weeks.