Date format in php [duplicate]

0

How to change the date format from 2016-2-26 to 2/26/2016. I already tried to use the format, but it did not work.

    
asked by anonymous 23.05.2018 / 23:44

2 answers

3
<?php
$time = strtotime('2016-2-26');

$data_formatada = date('d/m/Y',$time);

echo $data_formatada;

Will print:

  

2/26/2016

    
24.05.2018 / 05:56
0

Simplest way to do it, by working as String , transforming the date into an array with explode . I do not know if it helps you or if you wanted to work as a date. Follow below:

<?php

$data = '2016-2-26';
$array = explode('-', $data);
$data = $array[2].'/0'.$array[1].'/'.$array[0];
print($data);

Otherwise, please let me know if I can delete the answer.

    
23.05.2018 / 23:49