Page 1 of 1
A function - Check a date string whether valid.
Posted: Wed Jul 08, 2009 10:49 pm
by ctmaster
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.
Re: A function - Check a date string whether valid.
Posted: Wed Jul 08, 2009 11:44 pm
by iamngk
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";
}
Re: A function - Check a date string whether valid.
Posted: Thu Jul 09, 2009 10:19 am
by pickle
You might also be able to just throw that at strtotime()
Re: A function - Check a date string whether valid.
Posted: Thu Jul 09, 2009 3:06 pm
by Darhazer
iamngk wrote:yes it is possible with checkdate function in php.
please see the following code:
...
}
You can use list() to cut off few lines...
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.
Posted: Fri Jul 10, 2009 6:56 am
by iamngk
thanks Darhazer for your information.
