How to Convert PHP Date Into Mysql Date Format in php? -


this question has answer here:

i have tried convert following date mysql date format

accutual date : 01-01-17

php code

<?php  $datesrc =  '01-01-17';  echo date('y-m-d', strtotime($datesrc));  ?> 

result:

2001-01-17 

in case how handle type of date format(01-01-17 (d-m-y)), because got date format in user uploaded file..

<?php  $datestring = '01-01-17'; $mydatetime = datetime::createfromformat('d-m-y', $datestring); $newdatestring = $mydatetime->format('y-m-d');  echo $newdatestring; 

?>

you can this. first use datetime::createformat create datetime instance of time trying convert use normal php format change the format want

ps. work if know format of date want convert


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -