javascript
Brief description  about Online courses   join in Online courses
View Aman  Deep 's Profile

PHP CODE for date.........

<?php

$datein = '1998-09-21';
if(preg_match('/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/', $datein,$parts)){
print_r( $parts);
print_r($parts[2]."/" .$parts[1]."/" .$parts[0]);
}


?>

where i am mistaken in this code, as i am getting month and day well but for years, it show me full date........ please correct me or advice me to do in right manner.
Asked by Aman Deep | Sep 1, 2012 |  Reply now
Replies (1)
View jignesh soni 's Profile
Please use code below and it will give output as you need

<?php

$datein = '1998-09-21';
if(preg_match('/([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/', $datein,$parts)){
print_r( $parts);
echo "<br />";
print_r($parts[3]."/" .$parts[2]."/" .$parts[1]);
// print_r($parts[1]);
}

?>
Jan 15, 2013