Often we see Picard say to Riker: "You have the bridge Number 1", and I was wondering what the longest period of time that Riker was in command of the Enterprise-D for. I don't count just when he was acting-Captain (as in Best of Both Worlds), but also when Riker is in command whilst Picard is on an away mission.
Probably the longest period we have evidence that Riker was in command of the Enterprise would have been Gambit at the start of season 7 - Picard was first on leave, and then "murdered", and then a few days later Data took command after Riker was kidnapped.
However, there isn't a definite stardate reference until the start of the episode where the Enterprise is already investigating the initial disappearance of Picard, so we can't say exactly for how long Riker had command.
In the alternate timeline in All Good Things Admiral Riker had command of the Enterprise D probably for about 5 years. He mentioned they were going to decommission it 5 years ago, but his privilege as a admiral was to pick his ship.
If we're counting alternate timelines then we should certainly consider the gap between the invasion of Earth (by the Borg) and the events of TNG : Parallels. It seems that Riker has been in temporary command of the Enterprise for at least 3-5 years. Locutus (and his Borg chums) have overrun the Federation and it's unlikely that anyone's actually left to confirm his appointment to full captain.
If we're sticking with genuine timelines only (boo hiss) then it's almost certainly TNG: "Unification I & II" or TNG: "The Chase". In both episodes there's no specific stardates given but the Enterprise travels to multiple planetary locations under Riker's command which would strongly suggest that weeks (at least) may have passed.