Solved

varify date

Posted on 2007-03-23
3
208 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
[X]
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
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

751 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