The static formation temperature (SFT) is required to determine the thermophysical properties and production parameters in geothermal and oil reservoirs. However, the SFT is not easy to be obtained by both experimental and physical methods. In this paper, a mathematical approach to predicting SFT based on a new model describing the relationship between bottom hole temperature (BHT) and shut-in time was proposed. The unknown coefficients of the model were derived from least squares fit by Particle Swarm Optimization (PSO) algorithm. Besides, the ability to predict SFT based on a few BHT data (such as first 3, 4, or 5 ones of a data set) was evaluated. The accuracy of the proposed method to predict SFT was testified with a deviation percentage less than ±4% and high values of regression coefficient R2 (>0.98). The proposed method could be used as a practical tool to predict SFT in both geothermal and oil wells.