Bootstrap datepicker -- how to get date as a string in the right format? -
i'm using bootstrap datepicker. answer obvious, can't figure out how selected date string in specified format. used:
<div id="mydate" data-date-format="yyyy-mm-dd"> <input type="text"> </div>
and in javascript:
var value = $("#mydate").datepicker("getdate");
but returns date, not string in yyyy-mm-dd format.
the data-date-format="mm/dd/yyyy"
needs set on input:
<input type="text" data-date-format="mm/dd/yyyy">
your jquery should changed to:
var value = $("#mydate input").datepicker("getdate");
or can keep things simple no wrapping div
, original jquery work fine , wouldn't have specify input
:
<input type="text" id="mydate" data-date-format="yyyy-mm-dd">
suggestion
recommend creating class format datepicker. can add .datepicker
class input field , work without having specify variable.
fiddle
here working code alert of date http://jsfiddle.net/doitlikejustin/hfudg/1/
Comments
Post a Comment