I have always assumed that Rick was in the hospital for about 3 weeks. Several factors led me to this conclusion: The length of his beard; the fact that the IV bag was empty, but he didn't die of dehydration; the dead, completely dried out flowers on the table; the advanced state of decomposition of the bodies in and around the hospital; the timing of Lori's pregnancy; and so on.
But the answer to another question, apparently written by someone with medical training, made me think that a person with such training might be able to provide a more concrete answer, based on the visual clues in the hospital scenes.
Rick appears to have been receiving a maintenance IV of possibly 0.9 normal saline or Lactated Ringers to keep him hydrated due to fluid loss or possibly a hypertonic solution to decrease intracranial pressure if his coma resulted from respiratory failure. His medical condition would have been stablized prior to the ZA because he is not connected to a vent or any critical drips. The bag's volume appears to be 1000 ml and the rate of administration would be generally 50ml/hr for a man of Rick's size. This bag would take approximately 20 hours to complete before hanging a new bag.
He is not receiving tube feeding. He has no peg tube and no nasogastric tube to receive liquid calories, protein, fats and carbs. There is no feeding pump connected to the IV pole. He has no secondary IV bag or antibiotic hanging with the primary bag in the event of sepsis from his gunshot wound.
Also, Rick's coma probably did not result directly from the GSW. Comas unrelated to head trauma can be caused by metabolic abnormalities or they can be medically induced in patients who have suffered respiratory failure and require mechanical ventilation. An induced coma would be done by a Propofol drip through a central IV line. When these drips are stopped it only takes minutes for the patient to awaken.
The scene with Shane standing over Rick with the flowers makes it hard to determine how Rick is ventilated but there is no IV sedative hanging on the pole behind him and later Rick abruptly wakes up with only a nasal cannula in his nose. In a real world scenario Rick needs to wake up very soon to survive. One to two days after the ancillary staff have left the hospital.
So says someone who knows about medical treatment. I, on the other hand, don't even know if hospital staff would bother to shave a man in a coma, a question which could offer some insight into how long Rick's hospital stay was.
The wiki for TWD has a timeline for the show, in which it is said that Shane visited Rick on day 14 after the outbreak began, and that Rick woke up on day 59. This seems to be absolutely impossible, since Shane's visit coincided with the hospital's fall, and that would mean that Rick survived for 45 days without water; a difficult feat under any circumstances, but an impossibility in the heat of a summer in Georgia.
The show adds an even more formidable obstacle to the equation. In episode 5 of season one, Dr. Jenner at the CDC says:
It's day 194 since Wildfire was declared, and day 63 since the disease abruptly went global
This is extremely puzzling, because when Rick wakes up, he clearly knows nothing about the outbreak. When he was shot, he and Shane were chatting quite normally, and there was absolutely no indication that people were being devoured by zombies elsewhere in the country. One might expect that first responders like Rick and Shane would have been informed of something as important as the outbreak. So is the reason for their apparent ignorance that Rick was shot before the outbreak began, or were they in the dark because they simply weren't told about it?
[An additional tidbit of information can be gleaned from the promo for the new series Fear The Walking Dead, which is apparently set on the West Coast during the first days of the outbreak. While we don't know anything with certainty, the description of the show seems to suggest that the outbreak began in the U.S., which only makes the issue of why Rick didn't know about the crisis that much more confusing.]
Is there any way to determine how long Rick was in the hospital?
A video and some pictures of the relevant scene: