Computer >> Computer tutorials >  >> Programming >> PHP

checkdate() function in PHP


Tha checkdate() function validates a Gregorian date. It returns TRUE if the date is valid, FALSE otherwise.

Syntax

checkdate(month, day, year)

Parameters

  • month − Specifies the month as a number from 1 to 12

  • day − Specifies the day as a number from 1 to 31

  • year − Specifies the year as a number between 1 and 32767

Return

The checkdate() function returns TRUE if the date is valid, FALSE otherwise.

Example

The following is an example −

<?php
   var_dump(checkdate(10,29,2018));
?>

Output

bool(true)

Example

Let us see another example −

<?php
   $month = 9;
   $day = 30; $year = 2018;
   var_dump(checkdate($month, $day, $year));
?>

Output

bool(true)