Maximum: 4 years and 106 days
Depending on where you were in the world, however, the exact length of the war could vary . Different nations entered and exited the war at different times so although the war itself lasted over 4 years each country would, in practice, experience a different duration of fighting.
The Austro-Hungarian Empire may have had the longest war as they were the first to declare war and continued to fight through to November 1918 after which the state was dissolved as its minority nations sought independence.
A stranger case is the USA where the war technically lasted from April 1917 until Harding signed the Knox-Porter Resolution of 2 July 1921 because congress had failed to ratify the Treaty of Versailles in 1919.
Elsewhere even though the World War ended other regional conflicts continued for example in Russia, which was the first major power to withdraw from World War One, a bloody civil war would continue into the 1920s.
This situation was not unique to Russia and other Empires involved in the war saw conflict continuing after the war. The Ottoman and Austro-Hungarian Empires both ceased to exist in the wake of the war becoming divided between the victorious powers and their own national minorities.