You have a global variable value which is the current shortest time. At the end of a level you compare the level time with the current shortest time. If the level time is less than the current shortest time then that becomes the new current shortest time.
The current shortest time initial value can start initially as a high value e.g. 9999 so when the player sets their first time it is always going to become the new shortest time.