Issue
I have an array in which dates are likes 01/10/2015 22:53:00
or 08/19/2016
. i want to check that whether it is a date or not. If somebody put a text or other type in the field(Excel array), which i am putting into a variable, then it should generate an error that this is not a date.
I have searched but did not found success. Any help would be appreciated.
Solution
Try this (simple preg_match):
//your date
$date = '01/10/2015 12:12:23';
//check format
if(preg_match("/^[0-9]{1,2}\\/[0-9]{2}\\/[0-9]{4}$/", $date) OR preg_match("/^[0-9]{1,2}\\/[0-9]{2}\\/[0-9]{4} [0-9]{2}\\:[0-9]{2}\\:[0-9]{2}$/", $date)) {
echo 'OK';
}else {
echo 'BAD';
}
Answered By - Arkadiusz G. Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.