Do you need this:
$str1 = "1/22/2024";
$str2 = "1/22/24";
function get_needed_format($str) {
if(strlen(explode("/", $str)[2]) === 4) {
return substr($str, 0, -4).substr($str, -2);
}
return $str;
}
echo get_needed_format($str1);
echo "\n";
echo get_needed_format($str2);
?