Datetime-Local to Y-m-d format H: i: sP '?

0

I'm working on angular and I'm saving the datetime of two datetime-local with a ng-model

<input type="datetime-local" ng-model="column_Data.date_Start" placeholder="yyyy-MM-ddTHH:mm:ss" min="2014-01-01T00:00:00">

and then I am sending it via http to the controller to make a query that selects the start date and the end date of the query

$column_DB = DB::select("SELECT ".$Dato1." as dato, horaSistema FROM albatros_db2.".$Dato2." where horaSistema >= '".$date_Start."' and horaSistema <= '".$date_Finish."'");

The problem is that when I receive the data with the ng-model it appears with this format

Fri Jun 02 2017 10:01:38 GMT-0500 (Hora est. Pacífico)

I have no idea why I get that format and how I can change it to a more manageable format

Angular Driver Update

//Se obtiene las columnas de cada tabla
$scope.getColumn = function ()
{
    $scope.dataservice.data_Modify = [];
    var num_Column = 0;

    for (var i = 0; i < $scope.saveData.Column_Select.length; i++)
    {

        //Pedido a la ruta Reporte/consult_Report
        $http({
            method: 'GET',
            url: 'consult_Report' + 2 + "," + $scope.saveData.Column_Select[i].column +","
            +$scope.saveData.Column_Select[i].table+","+$scope.saveData.Column_Select[i].date_Start+","
            +$scope.saveData.Column_Select[i].date_Finish+''
        })
            .then(function (response)
            {
                $scope.data_Final = new Object();
                var value_Column = [];
                var date_Column = [];
                //Se recorre el objeto y se guardan los datos
                for (i_Data = 0; i_Data < response.data.length; i_Data++)
                {
                    value_Column[i_Data] = response.data[i_Data].dato;
                    date_Column[i_Data] = response.data[i_Data].horaSistema;
                }


                $scope.data_Final.name = $scope.saveData.Column_Select[num_Column].column+"--"+$scope.saveData.Column_Select[num_Column].table;
                $scope.data_Final.values = value_Column;
                $scope.data_Final.date = date_Column;
                $scope.dataservice.data.push($scope.data_Final);
                $scope.dataservice.data_Modify.push($scope.data_Final);

                num_Column = num_Column + 1;
            });
    }
    translation_Menu(3);
};
    
asked by Alejo Florez 02.06.2017 в 17:31
source

1 answer

2

It's the default date in JavaScript if I'm not mistaken, and I think it's independent of the format as well.

In my case, I use a function like this to convert it:

function formatoFecha(fecha) {
    var d = new Date(fecha),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear();

    if (month.length < 2) month = '0' + month;
    if (day.length < 2) day = '0' + day;

    return [day, month, year].join('-');
}

I leave you an example in plunker: link

You can remove or add information in that function so that the format corresponds to your needs.

I hope this is useful. Otherwise, do not hesitate to ask all the times you need.

    
answered by 02.06.2017 / 17:54
source