I have a php variable which contain date-time value like 2014-05-11 23:10:11
some times this may change, so i have to find it either it has date-time value or not, below is my variable
$my-variable='2014-08-26 18:25:47';
I have a php variable which contain date-time value like 2014-05-11 23:10:11
some times this may change, so i have to find it either it has date-time value or not, below is my variable
$my-variable='2014-08-26 18:25:47';
This should work for you to check if the string is a valid date time in your format:
<?php
$date = '2014-08-26 18:25:47';
function isTime($time) {
if (preg_match("/^([1-2][0-3]|[01]?[1-9]):([0-5]?[0-9]):([0-5]?[0-9])$/", $time))
return true;
return false;
}
$parts = explode(" ", $date);
list($y, $m, $d) = explode("-", $parts[0]);
if(checkdate($m, $d, $y) && isTime($parts[1]) ){
echo "OK";
} else {
echo "BAD";
}
?>
output:
OK