follow the topic, i wanna get a function for validating a date string whether valid or not.
for example "2009-02-02" is a valid date, but "2009-02-30" is a invalid date.
A function - Check a date string whether valid.
Moderator: General Moderators
Re: A function - Check a date string whether valid.
yes it is possible with checkdate function in php.
please see the following code:
$dt="02/28/2007";
$arr=split("/",$dt); // splitting the array
$mm=$arr[0]; // first element of the array is month
$dd=$arr[1]; // second element is date
$yy=$arr[2]; // third element is year
If(!checkdate($mm,$dd,$yy)){
echo "invalid date";
}else {
echo "Entry date is correct";
}
please see the following code:
$dt="02/28/2007";
$arr=split("/",$dt); // splitting the array
$mm=$arr[0]; // first element of the array is month
$dd=$arr[1]; // second element is date
$yy=$arr[2]; // third element is year
If(!checkdate($mm,$dd,$yy)){
echo "invalid date";
}else {
echo "Entry date is correct";
}
Re: A function - Check a date string whether valid.
You might also be able to just throw that at strtotime()
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: A function - Check a date string whether valid.
You can use list() to cut off few lines...iamngk wrote:yes it is possible with checkdate function in php.
please see the following code:
...
}
Code: Select all
$dt="02/28/2007";
list($mm, $dd, $yy) = split("/",$dt); // splitting the array
Re: A function - Check a date string whether valid.
thanks Darhazer for your information. 