I need to convert a variable
$date = 20130521201511
to
$date = 2013-05-21 20:15:11
however I am not quite sure how to do so.
This is achievable using the DateTime class.
$date = DateTime::createFromFormat("YmdHis","20130521201511");
var_dump($date);
Look closely at the documentation of the createFromFormat method to be sure to use the correct format parameters.
Use DateTime
php $oldDate= 20130521201511;
$date = DateTime::createFromFormat('YmdGis', $oldDate);
echo $date->format('Y-m-d G:i:s');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With