Most viral infections last between 2 to 3 weeks depending on the type of viral infection and how severe the viral infection you have is.
However if you do have a viral infection the viral infection should go away within 2 weeks at most and if not then you should see a doctor about it or go to urgent care to be sure it's not a more serious viral infection.
Some viral infections may only last a few days while other types of viral infections last 1 week to 2 weeks and in rare cases they can last up to a month.
Make sure you take some medication, get plenty of rest and stay hydrated and the viral infection should be gone after a few weeks.