Myth: If you drink coffee in the afternoon, you won't sleep at night.
Fact: For most people, an afternoon cup of coffee will not cause insomnia. That is, if you aren't drinking it after 3p.
Coffee has caffeine, so you need a bit of time for it to work its way out of your system, but in general that early afternoon coffee will not stop you from getting a good night of sleep.
According to SleepEducation.com;
"It has a half-life of 3 to 5 hours. The half-life is the time it takes for your body to eliminate half of the drug. The remaining caffeine can stay in your body for a long time. Effects can last from 8 to 14 hours."