0

I want to check the date string whether it is format d/m/Y. For eg. 23/07/2017.

how can I check as I required a condition in string. I am doing this.

echo $explode[2];
echo   date('d/m/Y', strtotime($explode[2]));
if (($explode[2] == date('d/m/Y', strtotime(trim($explode[2]))))) {
     echo "date format"; 
} else { 
     echo "error";
}
Bhinal Chauhan
  • 251
  • 3
  • 11
  • I have found a lot but not for this format. i.e. d/m/Y – Bhinal Chauhan Jul 20 '17 at 13:33
  • 1
    Possible duplicate of [Correctly determine if date string is a valid date in that format](https://stackoverflow.com/questions/19271381/correctly-determine-if-date-string-is-a-valid-date-in-that-format) – Nico Van Belle Jul 20 '17 at 13:35

1 Answers1

0
$explode[2];
$datePost =  $explode[2];
$datePost = str_replace('/', '-', $datePost);
if (($datePost == date('d-m-Y', strtotime($datePost)))) {
    echo "date format"; 
} else {
    echo "error";
}
Suneel Kumar
  • 1,650
  • 2
  • 21
  • 31
Bhinal Chauhan
  • 251
  • 3
  • 11