Date format in php

Asked

Viewed 40 times

0

How to change the format of the date 2016-2-26 to 02/26/2016. I tried using the format, but it didn’t work.

  • Ideally, put in the code you’ve already tried

2 answers

3

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

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

echo $data_formatada;

Will print:

26/02/2016

0

Simplest way to do, working as String, turning the date into an array with explode. I don’t 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);

If this is not the case, please inform me that I can delete the answer.

  • I found this way: date(’d/m/Y', strtotime($var))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.