- str_replace: documentation ( source)
<?php
$str_date = '12.31.2018';
try{
if($valid = (new \DateTime($str_date))){
echo $valid->getTimeStamp();
}
} catch(Exception $e){
try {
$str_date = (str_replace('.','/',$str_date));
if($valid = (new \DateTime($str_date))){
echo $valid->getTimeStamp();
}
} catch(Exception $e){
echo $e->getMessage();
}
}
?>