$dateString = "05.2018"; if (preg_match('/^\d+.\d\d\d\d/', $dateString)) { $date = date_create_from_format('!m.Y', $dateString); // ! sets the default values to lowest value possible. echo date_format($date, 'Y-m-d'); }
$dateString = "05.2018"; if (preg_match('/^\d+.\d\d\d\d/', $dateString)) { $date = date_create_from_format('!m.Y', $dateString); // ! sets the default values to lowest value possible. echo date_format($date, 'Y-m-d'); }