Home » PHP

PHP checkdate() function with example

PHP checkdate() function: Here, we are going to learn about the PHP checkdate() function with its syntax, parameters, returns type, and example.
Submitted by IncludeHelp, on August 13, 2019

PHP checkdate() function

checkdate() function is used to check the valid Gregorian dates. It accepts the date and returns Boolean values (True/False) based on the date values.

Syntax:

    checkdate(month,day,year);

Parameter(s):

  • month – It specifies the month in the numbers starting from 1 to 12.
  • day – It specifies the day in the numbers starting from 1 to 31.
  • year – It specifies the year in the numbers from 1 to 32767.

Return value:

It returns "TRUE" – if the date is valid, else it returns "FALSE".

Example: PHP code to check whether given date is valid Gregorian date

<?php

var_dump(checkdate(12, 31, 2019)); //valid
var_dump(checkdate(12, 31, -2018)); //invalid
var_dump(checkdate(2, 29, 2019)); //invalid
var_dump(checkdate(2, 29, 2020)); //valid

//checking through conditions
if (checkdate(12, 31, 2019)) echo "Valid\n";
else echo "Invalid\n";

if (checkdate(12, 31, -2018)) echo "Valid\n";
else echo "Invalid\n";

if (checkdate(2, 29, 2019)) echo "Valid\n";
else echo "Invalid\n";

if (checkdate(2, 29, 2020)) echo "Valid\n";
else echo "Invalid\n";
?>

Output

bool(true)
bool(false)
bool(false)
bool(true)
Valid
Invalid
Invalid
Valid

Reference: PHP checkdate() function







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.