varify date

Posted on 2007-03-23
Last Modified: 2007-03-24

Please assist how can we verify if the date is valid ?


Question by:FrankPorter
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

under_dog earned 250 total points
ID: 18778553
You want to use:

assuming the date is in the format you specify:

$myDateArray = explode("-", $mydate);

if (checkdate($myDateArray[2], $myDateArray[3], $myDateArray[1])) {

  echo "Date  is valid!";

} else {

  echo "Date is NOT valid!";


Author Comment

ID: 18778562
awsome! is it possible to make it a function that returns true or false?

if ( IsDate(#mydate)){}else{}
LVL 49

Assisted Solution

Roonaan earned 250 total points
ID: 18778827
function isDate($myDate) {
   if(!preg_match('/^(\d{4})\-(\d{2})\-(\d{2})$/', $myDate, $parts)) {
       return false;
    return checkdate($parts[1], $parts[2], $parts[0]);


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question