Answers for "php check if string is a date"

PHP
1

php check if input is date

function isRealDate($date) { 
    if (false === strtotime($date)) { 
        return false;
    } 
    list($year, $month, $day) = explode('-', $date); 
    return checkdate($month, $day, $year);
}
Posted by: Guest on November-08-2020
0

check date php

function validateDate($date, $format = 'Y-m-d')
{
    $d = DateTime::createFromFormat($format, $date);
    // The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue.
    return $d && $d->format($format) === $date;
}
Posted by: Guest on February-05-2022

Code answers related to "php check if string is a date"

Browse Popular Code Answers by Language