Change date format from d-m-y to d/m/Y

Initially I was using strtotime to fetch the desired format, but i was getting the initial time as 01/01/1970, then i realized(with little googling) that using strtotime expects string to be in format of y-m-d do we firstly need to convert this into this format. Below is the code for desired output.


$oldDate = '16-05-12';
$arr = explode('-', $oldDate);
$newDate = (string)($arr[2].'-'.$arr[1].'-'.$arr[0]);
echo date('d/m/Y',strtotime($newDate));

Advertisements
Posted in PHP

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s