How to convert String to Date in php? -


this question has answer here:

i trying date in d/m/y h:i format. here's code

$datestr = "28/07/2016 10:00"; echo date('d/m/y h:i', strtotime($datestr)); 

here's ouput:

01/01/1970 01:00 

i trying convert other formats, result still same date. know kind of obvious still can't understand why i'm getting date result.

you can use datetime class , it's createfromformat method parse string date in required format.

like this,

$date = datetime::createfromformat('d/m/y h:i', "28/07/2016 10:00"); $date = $date->format('y-m-d h:i:s'); echo $date; 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -