Answers for "validate year php"

PHP
1

regex to check date format php

if (preg_match("/\d{4}\-\d{2}-\d{2}/", $date)) {
    echo 'true';
} else {
    echo 'false';
}
Posted by: Guest on March-23-2020
1

How to check leap year in php?

$year = 2014;
// Leap years are divisible by 400 or by 4 but not 100
if(($year % 400 == 0) || (($year % 100 == 0) && ($year % 4 == 0))){
    echo "$year is a leap year.";
} else{
    echo "$year is normal year.";
}
Posted by: Guest on August-24-2020

Browse Popular Code Answers by Language