Solved

varify date

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now