Answers for "check if date is valid php"

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
1

php validate date format

$date="2012-09-12";

if (preg_match("/^(20[0-9]{2})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$date)) {
    return true;
} else {
    return false;
}
Posted by: Guest on September-21-2021
1

check if date is past php

$date = new DateTime($event['date']);
$now = new DateTime();
if($date < $now) {
    echo 'Date is in the past';
}
Posted by: Guest on March-27-2021
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 "check if date is valid php"

Browse Popular Code Answers by Language