Ok, I'm recovering from a recent surgery and I was told "heat". This totally goes against my college schooling so I will tell you what I learned.
Ice is for new injury..A sprained ankle, a pulled muscle. Anything that just happened, that is swollen and new. Ice it down.
How long? To penetrate deep enough to make a difference, it takes a full 20 minutes. Most people do not ice properly..don't wait long enough because of the discomfort. Its cold, uncomfortable, achy, and then finally knumb. You have to suffer through the initial stages to get to the benefit of it. Just deal with it...
Heat: To "relax" tight muscles or injuries that are chronic. What's chronic?--something that you've had for a while..something you plan on having for the rest of your life, etc. a "bad back" ...a weak area you repeatedly injure. In this case, use ice immediately, then switch over to heat once swelling is gone.
Exceptions to the rule: The back. A new back injury would receive heat. Why? I am told because of the many paraspinal muscles effected which would "go into spasms" with the shock of ice, heat is the preferred option. If you have swelling around the nerves causing your problem rather than just a muscular issue, the heat will not fix your problem. This is when a doctor or therapist could help with ideal positioning to use the body's weight to get things back into place & probably prescribe real medicine to speed up recovery.
DISCLAIMER: