The restricted mean survival time analysis has been used extensively in clinical research involving time-to-event endpoints. The threshold time up to which the restricted mean survival is calculated has a critical impact on the analysis results. However, identifying an optimal threshold time for treatment comparison, which corresponds to the greatest restricted mean lifetime difference between groups, remains unclear in practice and no analytical method has been developed on this topic. We present a novel method for determining the threshold time in the restricted mean survival time analysis to compare two groups. Simulation studies indicate that this method leads to high statistical power and controlled type I error rate compared with existing methods. The proposed method is illustrated in two applications: 1) a clinical oncology study for non-small-cell lung cancer treatments comparison given a programmed death-ligand 1 biomarker measurement, and 2) a gerontology study of instrumental activities for care recipients with dementia.