I have the following code:
<script type="text/javascript" language="javascript" src="~/Scripts/bootstrap-datepicker.min.js"></script>
<script type="text/javascript" language="javascript" src="~/Scripts/locales/bootstrap-datepicker.sv.min.js"></script>
<script type="text/javascript" language="javascript" src="~/Scripts/datareview.datatablestools.js"></script>
<script type="text/javascript">
$('.hospital_datepicker_From').datepicker({
format: "yyyy-mm-dd",
extraFormats: ["dd.mm.yy", "ddmmYYYY", "ddmmyy", "yyyymmdd"],
startDate: "2011-01-01",
language: "sv"
});
$('.hospital_datepicker_To').datepicker({
format: "yyyy-mm-dd",
extraFormats: ["dd.mm.yy", "ddmmYYYY", "ddmmyy","yyyymmdd"],
startDate: "2011-01-01",
language: "sv"
});
updateMinToDate = function () {
var toDate = $('.hospital_datepicker_To').datepicker('getDate');
var fromDate = $('.hospital_datepicker_From').datepicker('getDate');
if (toDate < fromDate) {
$('.hospital_datepicker_To').datepicker('update', '');
}
$('.hospital_datepicker_To').datepicker('setStartDate', fromDate);
};
clearDatePopover = function () {
$("#toDate").popover("hide");
}
Here Is my HTML:
<div class="input-group col-sm-3">
<input type="text" id="fromDate" name="FromDate" onchange="updateMinToDate(); clearDatePopover();" class="form-control hospital_datepicker_From" autocomplete="off" placeholder="ÅÅÅÅ-MM-DD" value="@(Model.StatisticHospitalFilter.FromDate.HasValue ? Model.StatisticHospitalFilter.FromDate.Value.ToString("yyyy-MM-dd") : string.Empty)" required />
<span class="input-group-addon">t.o.m.</span>
<input type="text" id="toDate" name="ToDate" class="form-control hospital_datepicker_To" autocomplete="off" onchange="clearDatePopover();"placeholder="ÅÅÅÅ-MM-DD" value="@(Model.StatisticHospitalFilter.ToDate.HasValue ? Model.StatisticHospitalFilter.ToDate.Value.ToString("yyyy-MM-dd") : string.Empty)" required />
</div>
I want to allow different formats to be entered In the datepicker, but I can't get It work.
When I enter a date In the format yyyymmdd, It just selects today's date, instead of the date that I entered In the format above.
How can I allow different date formats to be entered?
It doesn't seem possible with datepicker bootstrap. You have to put slash between your numbers when you enter a date.
Also how would datepicker make difference between your extraformats ["ddmmYYYY", "ddmmyy", "yyyymmdd"] and find which number is day, month or year ?
This could help however : http://bit.ly/1Zxstek
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.