TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to Disable Past Date Using Datepicker using JQuery
Bhushan Singh
Nov 05
2014
Code
18
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
date.zip
<script src=
"jquery.min_1.9.1.js"
></script>
<script src=
"bootstrap-datepicker.js"
></script>
<link rel=
"stylesheet"
type=
"text/css"
href=
"bootstrap-datepicker.css"
/>
<div
class
=
"form-group"
>
<input id=
"dp1"
type=
"text"
class
=
"form-control input-sm"
id=
"DtChkIn"
placeholder=
"Data CheckIn"
>
</div>
</div>
<div
class
=
"form-group"
>
<input id=
"dp2"
type=
"text"
class
=
"form-control input-sm"
id=
"DtChkOut"
placeholder=
"Data CheckOut"
>
</div>
</div>
<script>
var
nowTemp =
new
Date();
var
now =
new
Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
var
checkin = $(
'#dp1'
).datepicker({
beforeShowDay:
function
(date) {
return
date.valueOf() >= now.valueOf();
},
autoclose:
true
}).on(
'changeDate'
,
function
(ev) {
if
(ev.date.valueOf() > checkout.datepicker(
"getDate"
).valueOf() || !checkout.datepicker(
"getDate"
).valueOf()) {
var
newDate =
new
Date(ev.date);
newDate.setDate(newDate.getDate() + 1);
checkout.datepicker(
"update"
, newDate);
}
$(
'#dp2'
)[0].focus();
});
var
checkout = $(
'#dp2'
).datepicker({
beforeShowDay:
function
(date) {
if
(!checkin.datepicker(
"getDate"
).valueOf()) {
return
date.valueOf() >=
new
Date().valueOf();
}
else
{
return
date.valueOf() > checkin.datepicker(
"getDate"
).valueOf();
}
},
autoclose:
true
}).on(
'changeDate'
,
function
(ev) {});
</script>
disable past date