PHP checkdate () function verification date of validity example detailed

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.