- var_dump: documentation ( source)
- phpversion: documentation ( source)
- explode: documentation ( source)
- date: documentation ( source)
- strtotime: documentation ( source)
<<?php
function validarData($date, $format = 'Y-m-d H:i:s')
{
$version = explode('.', phpversion());
if ((int) $version[0] >= 5 && (int) $version[1] >= 2 && (int) $version[2] > 17) {
$d = DateTime::createFromFormat($format, $date);
} else {
$d = new DateTime(date($format, strtotime($date)));
}
return $d && $d->format($format) == $date;
}
var_dump(validarData('2014-02-31', 'Y-m-d'))
;