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

Asked

Viewed 232 times

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 he returns to me 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’t change the order of the date,: Y-dd-mm and I need it to be Y-mm-dd

Note: the date is coming from a Datepicker of the jquery

4 answers

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");

Thus, in the date_format you can put the format you want...

2


The Datepicker has input formatting:

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

Look in the documentation.

But if you want to invert 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}";
}

1

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;

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! http://api.jqueryui.com/datepicker/

Browser other questions tagged

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