Problem converting dates in PHP

Asked

Viewed 23 times

0

I have to compare dates to do various functions on the site, what takes the current time is this instruction:

date_default_timezone_set("America/Sao_Paulo");
$hora = date("d/m/Y H:i");

Returning 01/07/2017 18:28. I have the instruction that reads the database and converts:

$sel_hora_carrossel = $r_sql_car_1[0];
$sel_hora_carrossel_converte = date("d/m/Y H:i", strtotime($sel_hora_carrossel));   

Returning 07/01/2017 18:11 and I don’t know why or where else to look, because the dates don’t match, even though they both use the date_default_timezone_set("America/Sao_Paulo");.

  • which exactly means, in programming language, they don’t match?

  • Returns do not match. one returns "01/07/2017" and another returns "07/01/2017".

  • To confirm, what is the value of $sel_hora_carrossel? IS 01/07/2017?

  • It seems to me that the date is being recorded in the database in the format mm/dd/YY and as 1 is a valid month, it allows you to do the formatting as dd/mm/YY without error, but generating an unexpected result. You can confirm how you are saved in the database and what query is made to get this value?

  • One caution to be taken is with input type="date". Although the dd/mm/yyyy format will be typed in the field, this date will be saved to the seat in the yyyy-mm-dd format ....

No answers

Browser other questions tagged

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