mysql - Convert date mm-dd-yyyy to yyyy-mm-dd in php -


i want convert date field(format: dd-mm-yyyy) db date format. if input date format equal dd-mm-yyyy format convert date yyyy-mm-dd format else return false.

function converttodbdate($date) {     if($date !="") {         $result= date('y-m-d', strtotime(str_replace('/', '-', $date)));          if($result) {              return $result;          }          return false;     } }  

you can use datetime::createfromformat

$result_date = datetime::createfromformat('d/m/y', "23/02/2016");

echo $date->format('y-m-d');


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -