Date help in order printing

Asked

Viewed 39 times

1

I have a field in the table that is defined as dtConcat2 timestamp CURRENT_TIMESTAMP and in the insert it takes the date from the server and writes in this field, the problem when I print the invoice the date field comes out like this: Date of Request: 03 10:32:49/12/2017

My code is like this:

<strong>Data do Pedido:</strong>
<?php      
        echo implode('/',array_reverse(explode('-',$detalhe['dtConcat2'])));
?>

the time is in the middle between day and month, as I correct this to print the date correctly?

  • Has there been any response?

2 answers

0

I believe in your field the format is date and time, so first is to extract the date and then with the date format the output as you want, example:

<strong>Data do Pedido:</strong>
<?php      
   $data_hora = explode(' ',$detalhe['dtConcat2']);
   echo implode('/',array_reverse(explode('-', $data_hora[0])))." ".$data_hora[1];
?>

there is a way that is with date_format formatting the output of your date directly on SQL bank MySQL example:

SELECT *, DATE_FORMAT(dtConcat2, '%d/%m/%Y %H:%i:%s') as dtConcat2Formatada FROM table;

for example, I prefer to format the output on SQL.

References

  • Why have I been awarded -1? can someone explain so I can fix it? has any problem my answer?

  • Buddy, he doesn’t let change, he only opens -1 and -2, as I fix?

-1

You explode the hour before, through space...

$data = explode(" ", $detalhe['dtConcat2']);
echo implode('/',array_reverse(explode('-',$data[0])))." ".$data[1];

Browser other questions tagged

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