The value of the Datepicker (Daterangepicker) transformed to "Date" always shows me today's date

0

Greetings, I have a Datepicker which if I pick up the value directly (as a string)      var Data = $("#txtExpDataInici").val(); I take the values of the date well, but if I change it on date Date($("#txtExpDataInici").val()); always returns today's date on the date I choose ... Does anyone know what can happen?

    
asked by Xavier 03.03.2016 в 10:54
source

2 answers

2

I would recommend using the library moment.js this could be useful for parsing the date, instead of using Date() .

An example

var fecha = $("#txtExpDataInici").val();
var expDataInici = moment(fecha);

you can also indicate some format

var expDataInici = moment(fecha, "MM-DD-YYYY");
    
answered by 03.03.2016 / 11:26
source
0

Try this:

var fecha = new Date($("#txtExpDataInici").val());

If the value collected by the Datepicker for example is: 03/04/2016

"date" will be valid now:  Fri Mar 04 2016 00:00:00 GMT + 0100 (Romance Standard Time)

    
answered by 07.03.2016 в 13:03