Temporary fillings are not designed to last a long time. However there is no clock inside it to tell it to break or fall out by a certain date. Sometimes, it could last a very long time. Other times, a very short time. That doesn't answer the question at all! As a generality, a temporary filling should be changed within a couple of months.
What is a temporary filling?
The main difference in a temporary filling vs a normal filling, is the strength. Temporary fillings are easier to place, cheaper, weaker and uglier. It is designed to be a cheap filling just to maintain your comfort until a more long term restoration is made on the tooth.
What can you do to make a temporary filling last longer?
Fracture is the most common reason for a temporary filling to fail. A filling will not fracture if it isn't exposed to any physical stress. So, eating soft food and not biting on it will help it last longer. Keeping it clean with good oral hygiene will also greatly help.