Format date from variable with php

Asked

Viewed 629 times

-1

I have the variable below and want to format to the Brazilian standard (20/01/2015) using PHP.

$data = Sun Jan 10 00:00:00 CST 2016
  • Sun Jan 10 00:00:00 CST 2016 is the output of the variable. Then you need to see how it is declared. In this case I think you are using Datetime. To display for example today’s date in the format you want using date, is to simply do $data = date("d-m-Y");

  • It actually exits as an array: [x-Quiry-Arrival] => Sun Jan 10 00:00:00 CST 2016

  • Put the variable declaration...

  • php is reading this variable as a text and not as a date, how do I turn it into a date, then I do the formatting.

  • 2

    I think that this question can help you... On this other also.

1 answer

3


Convert that date by to timestamp with strtotime() and then take the desired format with date()

echo date('d/m/Y', strtotime('Sun Jan 10 00:00:00 CST 2016'));

Example - 3v4l

Browser other questions tagged

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