The code for datepicker is as follows:
$("#startDate").datepicker({
autoclose:true,
startView:"months",
minViewMode:"months",
orientation: "bottom",
format: "dd-MM-yyyy"
}).on('changeDate', function(selected){
startDate = new Date(selected.date.valueOf());
startDate.setDate(startDate.getDate(new Date(selected.date.valueOf())));
$('.to').datepicker('setStartDate', startDate);
});
$("#endDate").datepicker({
autoclose:true,
startView:"months",
minViewMode:"months",
orientation: "bottom",
format: "dd-MM-yyyy"
}).on('changeDate', function(selected){
FromEndDate = new Date(selected.date.valueOf());
FromEndDate.setDate(FromEndDate.getDate(new Date(selected.date.valueOf())));
$('.from').datepicker('setEndDate', FromEndDate);
});
The format which I get in front-end is:
01-January-2016
Now I need the format as:
Jan 2016
in the datepicker (front-end) box, whereas 01-01-2016 in the back-end. How can I do this? Please help me out guys.
You can simply change your datepicker (front end) format using
format
option specifyingM yyyy
instead ofdd-MM-yyyy
.Then you can use moment to convert your Date to a string using the format you need before sendind it to server. Here there is an example of converting date got from the datepicker to a string in the format
DD-MMMM-YYYY
using moment parsing function and momentformat
method.if you want to convert your date format any format use this library .
http://momentjs.com/