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
Solved

varify date

Posted on 2007-03-23
3
206 Views
Last Modified: 2007-03-24
Hi,

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

$mydate='2007-10-31';

Thanks.
0
Comment
Question by:FrankPorter
3 Comments
 
LVL 9

Accepted Solution

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

http://es2.php.net/checkdate

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!";

}
0
 

Author Comment

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

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

Assisted Solution

by:Roonaan
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]);
}

-r-
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 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