3

I'd like to validate UTC date, sent by the POST request, before inserting it into my database.

$date = "2014-08-11T16:32:13.000Z"

What is the best way to check if the date is correct?

akn
  • 3,712
  • 26
  • 43

1 Answers1

2
try {
  $dt = new DateTime($date);
  // $dt->format(DateTime::ATOM); // contains valid date
}catch(Exception $exception) {
  // invalid $date
}
clover
  • 4,910
  • 1
  • 18
  • 26