There are many ways that forensic scientists and doctors can use to determine how long ago someone died. One method is to measure the amount of contraction a muscle undergoes when excited by an electrical pulse. Depending on the amount of contraction will provide an estimate of time of death.
It can also be done by taking temperature measurements from different parts of the body to determine how long ago they died. As your body is normally at around 37 degrees after you die you will lose heat so the temperature will drop. The cooler you are the longer you’ve been dead, that’s why dead bodies are cold!
Forensic scientists can use a number of methods if the person died quite a long time ago. Warning – this answer gets a bit gross, I hope you’re not eating 😉
When people die, the body starts to decompose. This depends on the conditions (hot or cold, dry or damp). Insects such as flies are attracted to decomposing flesh and will lay eggs on the body. Fly eggs hatch into maggots. Scientists can use the type of maggots and the size/age of those maggots to work out how long the body has been dead for. This is called determining the post-mortem interval. There is a place in America called the Body Farm (University of Tennessee Anthropological Research Facility) where scientists take dead bodies and study what happens to them in a variety of conditions.
You can read about it: http://news.bbc.co.uk/1/hi/4638835.stm
I think you have to have a really strong stomach to do that kind of research.