1
Sirs, I have the following code:
$funcionario_blocodcon_novo = array();
for($i=0;$i<count($funcionario_blocodcon['localtrabalho']);$i++){
foreach($funcionario_blocodcon as $key=>$val){
if($funcionario_blocodcon['localtrabalhodata'][$i]==""){ $localtrabalhodata = "00/00/0000"; } else { $localtrabalhodata = $funcionario_blocodcon['localtrabalhodata'][$i]; }
$localtrabalhodata = date("Y-m-d", strtotime($localtrabalhodata));
$funcionario_blocodcon_novo[$i]['localtrabalhodata'] = $localtrabalhodata;
if($funcionario_blocodcon['datademissao'][$i]==""){ $datademissao = "00/00/0000"; } else { $datademissao = $funcionario_blocodcon['datademissao'][$i]; }
$datademissao = date("Y-m-d", strtotime($datademissao));
$funcionario_blocodcon_novo[$i]['datademissao'] = $datademissao;
$funcionario_blocodcon_novo[$i][$key]= $funcionario_blocodcon[$key][$i];
$funcionario_blocodcon_novo[$i]['idFuncionario'] = $ultimo_id;
}
}
In it, I need to format the dates that come from the date fields... But the first works normal and the second does not.
Results:
Array
(
[0] => Array
(
[localtrabalhodata] => 2015-12-07
[datademissao] => 01/02/2015
[localtrabalho] => 1
[idFuncionario] => 102
[segundaasextadas] => 08:00
[segundaasextaas] => 10:00
[sabadodas] => 18:00
[sabadoas] => 00:00
)
[1] => Array
(
[localtrabalhodata] => 2015-06-07
[datademissao] => 01/05/2015
[localtrabalho] => 13
[idFuncionario] => 102
[segundaasextadas] => 08:22
[segundaasextaas] => 11:02
[sabadodas] => 01:22
[sabadoas] => 02:33
)
)
What’s wrong? Can you do it another way? Thank you!
To help, add a portion of your original data. But from what I understand your problem is on this line here: $funcionario_blocodcon_novo[$i][$key]= $funcionario_blocodcon[$key][$i]; - Note that the $funcionario_blocodcon[$key][$i] will crash because your $id is the most external iterator and probably does not exist in this array.
– Gildonei
What value is coming in the field
$funcionario_blocodcon['datademissao'][$i]
before formatting?– Joel Rodrigues
Comes normal value: 01/05/2015
– Sr. André Baill
When I format, I define it in the dated $emittao it returns on the screen: 2015-05-01, however, at the time of entering the data, it inserts the one that was before... I tried to put the new dated $; as main, to define the value, equally... does not give. Strange that the first treatment of the site works right.... ...
– Sr. André Baill
So when displaying appears in the desired format? Are you using the same type of data for the two fields? If you are using the datetime type, formatting in the database is not important. This formatting will only be maintained if you are saving the data as text.
– Joel Rodrigues
I am using DATE. Normal, yyyy-mm-dd
– Sr. André Baill
So let’s go. At what point, really, would you like the date to appear formatted and it’s not? From what I understood in his previous reply it appears on the screen in the desired format, but is inserted in the original format. Are you seeing this original format when the date is entered in the bank? If yes, this is the standard of the bank and does not interfere with the results of its application.
– Joel Rodrigues
In the database, as the format is date, the return is: 0000-00-00, so I know that when entering it is going as original... and also by the debug I asked the question that the result is in the original format
– Sr. André Baill
Let’s go continue this discussion in chat.
– Sr. André Baill