Reputation: 135
Hello every one i have a problem with mysql dbms i never had a date storage in this format yyyy-mm-dd i always have it in this format dd-mm-yyyy i used this methode to change the date format while inserting data but it does not work
function dateConvert($dateInser) {
$dateTime = new DateTime($dateInser);
$dateFormate=date_format ( $dateTime, 'Y-m-d' );
return $dateFormate;
}
is there any solution ?
Upvotes: 0
Views: 1298
Reputation: 691625
The DateTime constructor also expects specific formats, and I doubt dd-mm-yyyy is one of them. First parse your dd-mm-yyyy date to transform it into a DateTime object, and then format this DateTime object using the yyyy-mm-dd format :
$dateTime = date_create_from_format('d-m-Y', $dateInser);
$dateFormate = date_format($dateTime, 'Y-m-d');
Upvotes: 3