Given that the senior officers on board the Enterprise, which of course included Data, Geordi, and Troi, would all have a daily staff meeting with the captain, it is highly likely that Data would have grown his beard within a day, which means he would also be able to grow his scalp hair at the same rate.
While the Enterprise operated on a three-shift rotation (except while under the command of Captain Jellico, who insisted on four shifts), Data would sometimes take command of the gamma or "night" shift because he didn't require sleep. He was usually assigned to the alpha shift as operations officer and would have seen Troi and Geordi within 24 hours.
It is possible that Data had taken some personal days off and grown it in while avoiding his best friend Geordi. However, it is much more likely that he simply grew it between shifts. Data has stated that he can control the speed at which the hair grows, but it is unknown what the limits of that speed are.