We now have a youtube channel. Subscribe!

PHP | checkdate() Function

PHP checkdate() Function


Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP checkdate() Function.

The PHP checkdate() function accepts the month, day & year of a date as parameters and, verifies whether it is Gregorian date or not.

Syntax

Following below is the syntax to use this function -

checkdate ( int $month , int $day , int $year )


Parameter Details

Sr.NoParameter & Description
1

month

This is an integer value representing the month of a date, it must be between between 1 and 12.

2

day

This is an integer value representing the day of a date, it must be below the allowed number of days in the given month.

3

year

This is an integer value representing the year of a date, it must be between between 1 and 32767.


Return Value

This built-in PHP function returns a boolean value. This value is TRUE if the given date is valid and, FALSE if it is invalid.

PHP Version

This function was first introduced as part of core PHP version 4, and works with all the later versions.

Example1

Following example below shows the usage of the PHP checkDate() function -

<?php
   var_dump(checkdate(11, 07, 1989));
   var_dump(checkdate(02, 31, 2008));
   
   $bool = (checkdate(06, 03, 1889));
   print($bool);
   print("\n");
   print("result: ".checkdate(13, 30, 2005));
?>

Output

When the above code is executed, it will produce the following result -

bool(true)
bool(false)
1
result:

Example2

In this example, we are trying to verify the dates of leap year(s) -

<?php
   var_dump(checkdate(02, 30, 2004));
   var_dump(checkdate(02, 28, 2008));   
   var_dump(checkdate(05, 31, 2020));
   var_dump(checkdate(06, 31, 2020));
?>

Output

When the above code is executed, it will produce the following result -

bool(false)
bool(true)
bool(true)
bool(false)

Example 3

Following example below verifies whether the date 12/12/2005 is Gregorian, or not -

<?php
   $bool = checkdate(12, 12, 2005);
   
   if($bool){
      print("Given date is valid");
   }else{
      print("Given date is invalid");
   }
?>

Output

When the above code is executed, it will produce the following result -

Given date is valid


Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP date_create() Function.

Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain