jquery datepicker onselect event shows invalid date in IE 11 - javascript

I have this code in my web application (see jsfiddle) ..
https://jsfiddle.net/6cgzuymh/2/
The problem is my users use both IE and chrome and this code works fine on chrome but not on IE 11.
and when I try to run the above jsfiddle on IE 11 it doesn't work. Does any body has any solution for this ?
The alert in first onselect method throws invalid date in IE but works fine in Chrome.
I have found one thing that if I remove the date format it works in IE as well, but I need dd-M-yy format as the client is from UK.
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
From:
</td>
<td>
<input type="text" id="txtFrom" />
</td>
<td>
</td>
<td>
To:
</td>
<td>
<input type="text" id="txtTo" />
</td>
</tr>
</table>
$("#txtFrom").datepicker({
changeMonth: true,
changeYear: true,
showAnim: "slideDown",
dateFormat: "dd-M-yy",
onSelect: function (selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate() + 1);
alert(dt); /// <<-------------------------------- throws invalid date in IE
$("#txtTo").datepicker("option", "minDate", dt);
}
});
$("#txtTo").datepicker({
changeMonth: true,
changeYear: true,
showAnim: "slideDown",
dateFormat: "dd-M-yy",
onSelect: function (selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate() - 1);
///$("#txtFrom").datepicker("option", "maxDate", dt);
}
});

Your date format is wrong. Instead of dd-M-yy you need to write yy-mm-dd.
$("#txtFrom").datepicker({
changeMonth: true,
changeYear: true,
showAnim: "slideDown",
dateFormat: "yy-mm-dd",
onSelect: function (selected) { }
});
https://jsfiddle.net/zfgh0ce2/
You want to make a date from new Date('04-Nov-2019') which isn't a IETF-compliant RFC 2822 or ISO 8601 date string.
-> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

Related

Trying to set date through air-date-picker

I am trying to add date picker but I am facing issue that Air DatePicker is showing date in both English and One more language I guess Russian
//Here it is code I am using for this
<input required type="text" class="form-control datepicker-here" id="textSchorOfficeOrderDate" autocomplete="off" data-language='en' data-date-format="yyyy-mm-dd">
//And Function for Date
$("#textSchorOfficeOrderDate").datepicker({
autoClose: true,
clearButton: true,
onSelect: function (formattedDate, date, inst) {
self.currentDate = date;
//It does't effct if I comment or not below line
self.onChangeMonthAndYear();
}
})
I want just English Language Date
Add language option in your script.I hope it will works for you.
$("#textSchorOfficeOrderDate").datepicker({
autoClose: true,
clearButton: true,
language: 'en', //add this line
onSelect: function (formattedDate, date, inst) {
self.currentDate = date;
//It does't effct if I comment or not below line
self.onChangeMonthAndYear();
}
})
This is ref link: http://t1m0n.name/air-datepicker/docs/

How can I disable the date selected previously for a reservation?

Im using the datetimepicker here (https://xdsoft.net/jqplugins/datetimepicker/)
I'm trying to a reservation, and I want that if the first datetime selected is the 20th of september at 12o'clock, i'd that in the second input I can only select of the previously selected day and above the previously selected hour
Can sombedy help please ? Thank's a lot in advance!
(the variable "nextDayReservation" is a date that's been been echo from the database, don't worry about it)
$("#datetimeFrom").datetimepicker({
minDate:nextDayReservation,
maxDate: '+1970/02/01',
format:'d/m/Y H:i', // d/m/Y H:i
minTime: '09:00',
maxTime: '22:00'
});
$("#datetimeTo").datetimepicker({
minDate:reservationDate,
format:'d/m/Y H:i',
maxDate: '+1970/02/01',
minTime:'09:00',
maxTime:'22:00'
});
Following works for date:
$("#datetimeFrom").datetimepicker({
format: 'Y/m/d H:i',
onShow: function(ct) {
this.setOptions({
maxDate: jQuery('#datetimeTo').val() ? jQuery('#datetimeTo').val() : false,
})
}
});
$("#datetimeTo").datetimepicker({
format: 'Y/m/d H:i',
onShow: function(ct) {
this.setOptions({
minDate: jQuery('#datetimeFrom').val() ? jQuery('#datetimeFrom').val() : false,
})
}
});
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.js"></script>
<input id="datetimeFrom" type="text">
<input id="datetimeTo" type="text">

How to get jQuery datepicker to show months even while using Bootstrap

I have a page that includes a jQuery datepicker and I include the bootstrap CSS files, which helps the display look better. However, the months and years are not showing like in this question: here
I don't want to remove the bootstrap files to fix the problem. Is there any way to fix it while still including them?
<td>DOB - Age:</td>
<td>
<table>
<tr>
<td>
#Html.TextBoxFor(x=>x.Dob, new { id = "txtdob", style = "width:100px"}) <br />
#Html.ValidationMessageFor(x=>x.Dob)
</td>
<td>
#Html.TextBoxFor(x => x.Age, new { id = "txtAge", style = "width:30px"})<br />
#Html.ValidationMessageFor(x => x.Age)
</td>
</tr>
</table>
</td>
//birth date - no future dates and go back 100 years, set age
$("#txtdob").datepicker({
changeMonth: true,
changeYear: true,
yearRange: "-100:+0",
maxDate: '+0d',
onSelect: function (date) {
var dob = new Date(date);
var today = new Date();
var age = today.getFullYear() - dob.getFullYear();
$("#txtAge").val(age);
}
});

Put age restriction of 18 years - Bootstrap Datepicker

I am using Bootstrap Datepicker.
I want to put an Age Restriction of 18 Years.
Dates less than Age 18 Years from current date should be disabled.
Here is my Fiddle:
http://jsfiddle.net/kGGCZ/17/
JS:
$(function()
{
$('#datepicker').datepicker(
{
viewMode: "years",
defaultDate: '-2yr',
}
);
});
Simply put endDate: '-18y' if you only want to allow user whose age is 18 years and above.
<input type="text" class="datepicker">
<script>
$('.datepicker').datepicker({
endDate: '-18y'
});
</script>
Working Example: https://jsfiddle.net/sparshturkane/w46euf5q/1/
Please refer Bootstrap Date picker docs for more options and instructions
This is the JavaScript you are after:
var dt = new Date();
dt.setFullYear(new Date().getFullYear()-18);
$('#datepicker').datepicker(
{
viewMode: "years",
endDate : dt
}
);
But your fiddle is using coffeescript so here is the same in coffee:
dt = new Date()
dt.setFullYear new Date().getFullYear() - 18
$("#datepicker").datepicker
viewMode: "years"
endDate: dt
working example: http://jsfiddle.net/Ln5x6/1/
You can use yearRange, to let users choose only years which comes under 18+ from current year. Like,
jQuery('#dateob').datepicker({
changeMonth: true,
changeYear: true,
yearRange: '-110:-18',
showButtonPanel: true
});

datetimepicker and dateFormat: unexpected format

I would like the date in the following format:
yyyy-mm-dd HH:mm:ss (2013-02-01 12:12:12)
This is how I'm trying:
$('#start_date,#end_date, #date').datetimepicker({
dateFormat: 'yyyy-mm-dd',
timeFormat: 'HH:mm:ss',
onSelect: function(value){
alert(value);
}
});
The problem is that onSelect i get: yyyyyyyy-mm-dd HH:mm:ss (20132013-02-01 12:12:12)
what am I doing wrong?
Try the following
dateFormat: 'yy-mm-dd',

Categories

Resources