Verifying date format
Moderator: General Moderators
feyd | Please use
and for calling iut useing
MyCheckDate($test);
$test = "1989-12-12"
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
this 1Code: Select all
function MyCheckDate( $postedDate ) {
if ( preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $postedDate) ) {
list($year , $month , $day) = explode('-',$postedDate);
return checkdate($month , $day , $year);
} else {
return false;
}
}MyCheckDate($test);
$test = "1989-12-12"
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
use the other function instead...
Code: Select all
function MyCheckDate( $postedDate ) {
if (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $postedDate, $datebit)) {
return checkdate($datebit[2] , $datebit[3] , $datebit[1]);
} else {
return false;
}
}feyd | Please use
not doin anythin i must be doin sumthin wrong
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
this is correct yes ?Code: Select all
<?
$test = '12-12-2008';
MyCheckDate( $test );
function MyCheckDate( $postedDate ) {
if (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $postedDate, $datebit)) {
return checkdate($datebit[2] , $datebit[3] , $datebit[1]);
} else {
return false;
}
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Code: Select all
<?
$test = '2008-12-12';
MyCheckDate( $test );
function MyCheckDate( $postedDate ) {
if (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $postedDate, $datebit)) {
print_r($datebit);
return checkdate($datebit[2] , $datebit[3] , $datebit[1]);
} else {
return false;
}
}
?>