How to format results display

Asked

Viewed 124 times

1

I need to show table data as date, I just don’t know how to do the conversion.

It returns the result as it is in the database: 00000000 and I need to get back to 00/00/0000

I have the following code:

<?php while ($linha = mysqli_fetch_assoc($select)): ?>
    <table>
         <tr>
             <th>Data:</th>                         
             <td><?php echo $linha['DATA'] ?></td>
         </tr>
    </table>
<?php endwhile; ?>

Man $select only has the SELECT * FROM.

  • In the bank is 00000000 same or is 0000-00-00?

  • why in the database you do not save date instead of string? and even if it is string, why remove formatting?

2 answers

2


To format dates in PHP, you can use the function date:

date('d/m/Y', strtotime($linha['DATA']));
  • It worked here. Thank you very much, I’ll already be accepting the answer.

  • It would have to format a number as well?

  • How are you returning your CPF? @Pedrohenrique Please check as solved.

  • 00000000000 also

  • $cpfMask = "%s%s%s. %s%s%s. %s%s s-%s%s"; echo format($cpfMask ,'07412171631'); output: 074.121.716-31

  • php has no function ready for our Cpf, so we use this value that it expects a past variable

  • Okay thanks really man!!

Show 2 more comments

2

The solution would be as follows:

<?php $novadata = date('d/m/Y', strtotime($linha['DATA'])); ?>
<td><?php echo $novadata ?></td>

strtotime to convert to time with / or -, save to a php variable and print it then.

Browser other questions tagged

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