We all know that there are 12 months in a year, one months have 31 days (or 30 days, February has 28 days, leap year February has 29 days), one weeks have 7 days, 24 hours a day ... Wait a minute. But our computer does not know Ah, it is not able to distinguish the right and wrong data, so, can only rely on the features provided by developers to perform or check. Use the Checkdate () function in PHP for date checking, this chapter we will explain to you
the "checkdate ()" function.
Checkdate () function syntax:
The Checkdate () function is the validity of the check date, and its syntax is as follows:
Checkdate (month, day, year)
Syntax Explanation:
Returns TRUE if the given date is valid, otherwise FALSE is returned.
It has three parameters: where month's valid value is 1~12;day's valid value is the maximum number of days of the month, for example, January is 31 days, February is 29 days (leap year), and the valid value of year is from 1~366.
Checkdate () Function instance
We use the Checkdate () function to check for a correct date, an incorrect date, and the code is as follows:
First check the date of the pair:
<?phpheader ("Content-type:text/html;charset=utf-8"); Set the encoding $year=2017; Year $month=4; $day =30;var_dump (Checkdate ($year, $month, $day));? >
Running results such as:
Here we use the checkdate () function to check the date of an error, we see that the above example knows that April has 30 days, we now change 30 to 31 days, the code is as follows:
<?phpheader ("Content-type:text/html;charset=utf-8"); Set the encoding $year=2017; Year $month=4; $day =31;var_dump (Checkdate ($month, $day, $year));? >
Running results such as:
You can also write the date directly in the Checkdate () function
<?phpheader ("Content-type:text/html;charset=utf-8"); Set Encoding Var_dump (Checkdate (12,4,2017));? >
This is the simple use of the checkdate () function, and the next section, we explain the formatting options for the parameter format of the date () function.