Date going wrong

Asked

Viewed 70 times

2

I saw similar questions, but none with answer, my date is coming so from the bank 2017-05-05T00:00:00+00:00 when I try to make a date(’d-m-Y',strtotime($data)); it comes so 04-05-2017, has it come 05-05-2017? Why does this happen? Why does she return one day?

echo date('d-m-Y',strtotime($publicacao['dataPublicacao']));

Here takes from the bank through the publish token and id and returns a json

  function getSinglePublicacao($id){

session_start();
include_once "token.php";

$token = getToken($_SESSION['username'],$_SESSION['password']);

ob_start();

$ch = curl_init();

curl_setopt( $ch, CURLOPT_URL, 'http://politizar.azurewebsites.net/api/cadastro/publicacao/getSingle/'.$id ); 

curl_setopt( $ch, CURLOPT_HEADER, 0 );

curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token ) );

curl_exec( $ch );

$data = ob_get_contents();

ob_end_clean();

$httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );

curl_close( $ch );

    return json_decode($data, true);

}

And here was my attempts, Bs the return of publishing['dataPublication']; returns 2017-05-05T00:00:00+00:00

e o resto retorna a data faltando um dia

$partidos = listarPartido($token_access);

$idPublicacao = $_GET['idPublicacao'];

$publicacao = getSinglePublicacao($idPublicacao);
print_r($publicacao);
$cidades = listarCidades($token_access);

echo str_replace("-","/",date('d-m-Y',strtotime($publicacao['dataPublicacao'])));
echo str_replace("-","/",date('d-m-Y',$publicacao['dataPublicacao']));
echo "<br>";
echo date('d-m-Y',strtotime($publicacao['dataPublicacao']));
echo "<br>";
echo $publicacao['dataPublicacao'];
  • In the Ideone the result was 05-05-2017. Are you sure that the value is coming from the database? What version of PHP?

  • The version is 5.4 and yes it’s coming from the bank @Andersoncarloswoss will be something I did wrong?

  • look at how Anderson said: https://ideone.com/Uf7nZ3 it’s not as if the value returned from the database is like this, and then it’s not php version maybe it’s confusion or even typo, take a better look!

  • And which is the Timezone configured? The information stored in the database and in PHP are the same?

  • I don’t know @Andersoncarloswoss how I put the same php?

  • 1

    @Virgilionovic No... it’s not a typo because I copied and pasted the return here... it’s coming anyway

  • Strange @Andersonhenrique very strange. I believe I do not know can be wrong has nothing to do with Timezone, because the date is not requested from the system the date is a value brought from the bank. Now I’m curious

  • You have the full chunk of that code?

  • 1

    I do have @Virgilionovic I will edit the question 1 minute

  • 1

    Edited by @Virgilionovic

Show 5 more comments

1 answer

0

Hello!!

There seems to be something wrong with your code, I performed a test here and passing that date the value returns correctly.

Try using Datetime. Ex:

<?php

$d = new DateTime('2017-05-05T00:00:00+00:00');
echo $d->format('d-m-Y');

Browser other questions tagged

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