I tried another code PHP: $second = ($time - 170) % 60; $timer = ($time - 170 - $second) / 60; $min = $timer % 60; $sec = str_pad($second, 2, "0", STR_PAD_LEFT); it worked but it continues to negative