We all know that there are 12 months in a year, 31 days in a month (or 30 days, 28 days in February, and 29 days in February in leap years), 7 days in a week, and 24 hours in a day.. ....etc. But our computer doesn't know. It can't tell whether the data is right or wrong. Therefore, it can only rely on the functions provided by the developer to execute or check. Use the checkdate() function in PHP to check the date. In this chapter, we will explain to you the"checkdate()" function.
checkdate() function syntax:
The checkdate() function checks the validity of the date. Its syntax is as follows:
checkdate (month , day ,year )
Detailed syntax:
Returns TRUE if the given date is valid, otherwise returns FALSE.
It has three parameters: the valid value of month is 1~12; the valid value of day is the maximum number of days in the month, such as January is 31 days, February is 29 days (leap year); the valid value of year Values range from 1 to 366.
checkdate() function example
We use the checkdate() function to check a correct date and an incorrect date, The code is as follows:
First check the correct date:
The running result is as follows:
Next we use the checkdate() function Let's check an incorrect date. Let's look at the above example and know that April has 30 days. Now we change 30 to 31 days. The code is as follows:
The running result is as follows:
You can also write the date directly in the checkdate() function
The above is a simple application of the checkdate() function. In the next section, we will explain the parameter format of the date() function. Formatting options.
The above is the detailed content of Detailed explanation of the validity example of php checkdate() function checking date. For more information, please follow other related articles on the PHP Chinese website!