Using jquery and the Bootstrap Datepicker, how do I get the new date value I selected using the Bootstrap Datepicker? FYI, I\'m using Rails 3 and Coffescript.
I set
You can try this
$('#startdate').val()
or
$('#startdate').data('date')
Bootstrap datepicker (the first result from bootstrap datepickcer search) has a method to get the selected date.
https://bootstrap-datepicker.readthedocs.io/en/latest/methods.html#getdate
getDate: Returns a localized date object representing the internal date object of the first datepicker in the selection. For multidate pickers, returns the latest date selected.
$('.datepicker').datepicker("getDate")
or
$('.datepicker').datepicker("getDate").valueOf()
There are many solutions here but probably the best one that works. Check the version of the script you want to use.
Well at least I can give you my 100% working solution for
version : 4.17.45
bootstrap-datetimejs https://github.com/Eonasdan/bootstrap-datetimepicker Copyright (c) 2015 Jonathan Peterson
JavaScript
var startdate = $('#startdate').val();
The output looks like: 12.09.2018 03:05
Try this using HTML like here:
var myDate = window.document.getElementById("startdate").value;
If you already have a number of dates already highlighted and want to determine which date was last clicked then you'll need the following:
$('#startdate').data('datepicker').viewDate
viewDate
returns a JavaScript date object so you'll need to handle it accordingly.
$("#startdate").data().datepicker.getFormattedDate('yyyy-mm-dd');