For shuttle at least, I believe the longest delay was the torturous launch flow of STS-35. (tl;dr it was delayed six months.)
Using the criteria in the Space Shuttle Missions Summary, namely
Postponements are defined as launch delays which occurred prior to call-to-stations for OMI S0007 Shuttle Countdown.
Scrubs are launch date changes after the start of Shuttle countdown (countdown was terminated or recycled to a later launch date).
Delays are delays which occur only on the day-of-launch.
So this is about delays & scrubs that happened after the vehicle was stacked and rolled out to the pad, not about postponements, i.e. changes in the planned launch date before the vehicle was stacked.
The first official launch date for STS-35 was May 30, 1990. During tanking on that day, hydrogen leaks were detected at the orbiter / external tank (ET) interface. After a tanking test on June 6, a pad repair was deemed undoable so the stack was rolled back to the Vehicle Assembly Building (VAB) on June 13. Columbia was removed from the stack and moved back to the Orbiter Processing Facility. The umbilicals on both the orbiter and ET were changed out.
The orbiter was returned to the stack and it rolled back to the pad on August 9 for a September 1, 1990 launch date (94 days after the first attempt).
Issues with the payload then caused a slip to September 4, 1990 (98 days after the first attempt). During tanking on that day...hydrogen leaks were again detected. heavy sigh from everyone in the program. Work started in orbiter aft compartment to track down and fix leaks.
After aft compartment work was completed the next attempt was September 17, 1990 (110 days after the first attempt). During tanking on that day...hydrogen leaks were again detected. very heavy sigh from everyone in the program.
The STS-35 stack was then rolled to Pad B so Atlantis could launch on STS-381 as planned from Pad A. Then there was a tropical storm (Klaus) which forced the stack to be rolled back to the VAB yet again. Back to pad B on October 14, 1990. On October 30 a tanking test was conducted. No leaks!
The launch date was then set for December 2, 1990 (186 days after the first attempt). Tanking went well - no leaks - and after a brief range delay, it finally launched. sigh of relief from everyone in the program.
Additional reference: NASA STS-35 Mission Page
STS-35 and STS-38 passing each other to and from the VAB on the crawlerways during the "summer of leaks". Photo credit-NASA
Related:
1 The referenced NASA page is wrong about the mission that forced the pad switch (it says STS-36). I originally thought it was STS-41, which was the 36th flight, and that they were confused by the "36th flight",but even that is wrong. STS-41 (10/6/1990) and STS-38 (11/15/1990) both launched during STS-35's launch campaign, and STS-41 launched off Pad B as planned. STS-38 launched off Pad A. STS-36 had already launched in February 1990. It was a very confusing summer.