Error with changing date format

0

I made a system that saves the date in Y-m-d format, both the entry and the exit date. What I did to give back that format is take the date in a variable and use strtotime , like this:

<?php
$originalDates = $row['ingreso'];
$originalDates. = $row['salida'];
$salida = date("d-m-Y", strtotime($originalDates));
?>
Ingreso el dia <b><?=$salida;?></b>
Finaliza el dia <b><?=$salida;?></b>

But error comes when I concatenate the variable to change the exit date and when I do this it does not give me any error, but nothing appears on the page.

    
asked by Stn 13.12.2018 в 15:27
source

3 answers

3

You must make the change of each date independently:

Ingreso el dia <b><?php echo date("d-m-Y", strtotime($row['ingreso']));?></b>
Finaliza el dia <b><?php echo date("d-m-Y", strtotime($row['salida']));?></b>

If you concatenate, you have an element that is "incomeallows" and does not know how to interpret it as valid data.

    
answered by 13.12.2018 / 15:43
source
1

I improved the solution:

<?php
$fechaIngreso = date("d-m-Y", strtotime($row['ingreso']));
$fechaSalida = date("d-m-Y", strtotime($row['salida']));
?>
Ingreso el día: <b><?=$fechaIngreso;?></b>
Finaliza el día: <b><?=$fechaSalida;?></b>
    
answered by 13.12.2018 в 15:32
0

You have a syntax error a point more than $ originalaDates, I tried the following and it works perfect, the other would be to see that it carries the variable $row[]

<?php
$row['ingreso'] = date("F j, Y, g:i a"); // esta es la fecha de ahora
$row['salida'] = date("F j, Y, g:i a");
$originalDates = $row['ingreso'];
$originalDates = $row['salida'];
$salida = date("d-m-Y", strtotime($originalDates));
?>
Ingreso el dia <b><?=$salida;?></b>
Finaliza el dia <b><?=$salida;?></b>
    
answered by 13.12.2018 в 15:46