Sam: 62 years, Gimli: 121 years (maybe)
According to Appendix B of the Lord of the Rings, it is in Shire Reckoning (S.R.) 1420 that Bilbo and Frodo go over the sea. This year is the end of the Third Age of Middle Earth.
Sam goes back to the Shire, where he lives a long life and is elected Mayor of the Shire 7 times. In S.R. 1482 following the death of his wife Rose, on September 22, 62 years after Frodo ...
Master Samwise rides out from Bag End. He comes to the Tower Hills, and is last seen by Elanor ..... the tradition is handed down from Elanor that Samwise passed the Towers, and went to the Grey Havens and passed over the Sea, last of the Ring Bearers.
In S.R. 1541, so 121 years after Bilbo and Frodo ....
Legolas built a grey ship in Ithilien and sailed down Anduin and so over the sea; and with him, it is said, went Gimli the dwarf
So neither case is absolutely confirmed by the book - but the times are 62 and 121 years - significantly after the events of the movies, which start in 1401 (Bilbo's birthday party), with the destruction of the Ring in 1419 and end in 1420 (Bilbo and Frodo leave).