Solved

varify date

Posted on 2007-03-23
3
203 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

832 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