It's true that gasoline is more dense when it's cold, which means typically it's most dense in the early morning hours when it tends to be coolest outside. Thus, there's solid reasoning behind the theory (or urban legend, if you prefer) that it makes the most financial sense to fill up your car at the pump in the morning. However, unfortunately, reality doesn't play out that way.
First off, assuming it mattered when you bought your gasoline, what difference does it make? Well, gasoline is sold by the gallon in the United States. (Even in other parts of the world, it's sold based on volume, even though the measurements differ, so the same principles apply.) However, the density of gasoline changes based on its temperature. Colder gasoline is more dense than warmer gasoline, so another way to look at it is that a cold gallon of gas contains more energy than a warm gallon of gas, even though they might cost the same. And that's why this theory appeals to the budget-conscious among us.
Even though the science is sound, the actual density change of gasoline is so small that it's impractical to change schedules just to obtain fuel super early in the morning. For one thing, most gas stations store their fuel underground, in heavily insulated tanks. According to a study by Consumer Reports, the small amount of gas that sits above ground in the lines might warm up if it sits there long enough. But if the gas is flowing smoothly on a busy day, it won't matter. And even if there is a lull between customers, those few slightly-warmer gallons won't affect the value of a whole tank.
The aforementioned Consumer Reports investigation also found that gasoline that rises in temperature from 60 degrees to 75 degrees Fahrenheit only increases in volume by 1 percent [source: Hard]. When gas prices are reasonably low, that won't affect the per-gallon price much, probably just a few cents averaged out over a full fill-up. So someone who was driving out of the way to fill up in the early morning would probably burn up more fuel going off course than they'd be likely to save. Even though gasoline should be the most dense in the morning (or whenever air temperatures are the coolest) there are several other factors at work preventing this from being an effective, cost-saving fill-up strategy.