How to change the date order of an implode coming from a jquery datepicker

2

I have the following $ _get:

if(!empty($_GET) && $_SERVER['REQUEST_METHOD'] == 'GET'){
    $v_ocorrencia = $_GET['ocorrencia'];
    $datainicio = $_GET['datainicio'];
    $datafinal  = $_GET['datafinal'];

echo 'valor recebido: '. $v_ocorrencia;
    echo 'valor recebido: '. $v_datainicio." 00:00:00.000";
        echo 'valor recebido: '. $v_datafinal." 00:00:00.000";

With the implode it returns the date:

valor recebido: 1
valor recebido: 2016-17-11 00:00:00.000
valor recebido: 2016-26-11 00:00:00.000

So far so good, but I can not change the order of the date, it's coming out: Y-dd-mm and need to be Y-mm-dd

Note: The date is coming from a jquery datepicker

    
asked by anonymous 01.11.2016 / 20:07

4 answers

2

Datepicker has input formatting:

var date = $('#datepicker').datepicker({ dateFormat: 'yy-mm-dd' }).val();

Look in the documentation .

But if you want to flip only in php, just format the value:

$valor = '2016-17-11 00:00:00.000';

formatDateEng($valor);

function formatDateEng($valor)
{
    list($dateStr, $timeStr) = explode(' ', $valor);
    list($y, $d, $m) = explode('-', $dateStr);
    return "{$y}-{$m}-{$d} {$timeStr}";
}
    
01.11.2016 / 20:50
2

Try the following:

$v_datainicio=date_create($v_datainicio." 00:00:00.000");
$v_datafinal=date_create($v_datafinal." 00:00:00.000");
echo 'valor recebido: '. date_format($v_datafinal,"Y-d-m H:i:s");
echo 'valor recebido: '. date_format($v_datafinal,"Y-d-m H:i:s");

This way, in date_format you can put the format you want ...

    
01.11.2016 / 20:18
1

The datepicker does not modify the order. This is coming from your request . Just deal with PHP:

list($ano,$dia,$mes) = explode("-",v_datainicio);
$nova_data = $ano.'-'.$mes.'-'.$dia;
    
01.11.2016 / 20:18
1
 $( ".selector" ).datepicker({
 changeYear: true
});

/ Getter
 var defaultDate = $( ".selector" ).datepicker( "option", "defaultDate" );

// Setter
$( ".selector" ).datepicker( "option", "defaultDate", +7 );

Take a look here and see if it helps! link

    
01.11.2016 / 20:19