I need to get the value of Datetimepicker in my JavaScript function. I have made something like this, but it doesn't work:
$("#date").click( function(){
alert(document.getElementById('datetimepicker1').value);
});
It gives me 'undefined'
I need to get the value of Datetimepicker in my JavaScript function. I have made something like this, but it doesn't work:
$("#date").click( function(){
alert(document.getElementById('datetimepicker1').value);
});
It gives me 'undefined'
Or try $("#datetimepicker").data().date;
Either use:
Or (from looking at the page source):
The returned value will be a
Date
(for the first example above), so you need to format it yourself:Also, you could just set the format as an attribute:
and you could use the
$("#datetimepicker1").find("input").val();
I'm using the latest Bootstrap 3 DateTime Picker (http://eonasdan.github.io/bootstrap-datetimepicker/)
This is how you should use DateTime Picker inline:
The above returned: 03/23/2017
It seems the doc evolved.
One should now use :
$("#datetimepicker1").data("DateTimePicker").date()
.NB : Doing so return a Moment object, not a Date object
To call the Bootstrap-datetimepikcer supported functions, you should use the syntax:
So you can try the function:
Documentation: http://eonasdan.github.io/bootstrap-datetimepicker/Functions/
Since the return value has changed,
$("#datetimepicker1").data("DateTimePicker").date()
actually returns a moment object as Alexandre Bourlier stated:Therefore, we must use .toDate() to change this statement to a date as such:
$("#datetimepicker1").data("DateTimePicker").date().toDate();