# Restricting Dates on Calendar

**URL:** <https://forums.knack.com/t/restricting-dates-on-calendar/10312>\
**Category:** API & Custom Code\
**Created:** [February 27, 2015, 7:56pm UTC](https://forums.knack.com/t/restricting-dates-on-calendar/10312 "2015-02-27T19:56:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CraigDavid59736](https://avatars.discourse-cdn.com/v4/letter/c/dc4da7/32.png) [@CraigDavid59736](https://forums.knack.com/u/CraigDavid59736)\
**Post date:** [February 27, 2015, 7:56pm UTC](https://forums.knack.com/t/restricting-dates-on-calendar/10312/1 "2015-02-27T19:56:50Z")

</div>

Thanks to Nicolas for helping out on this one:

&nbsp;

```
$(document).on('knack-view-render.view_xx', function (event, view, data) {

```
$('#view_xx-field_xxx').datepicker('option', {
	maxDate: 0
});

```

});
```

&nbsp;

This will make the user unable to pick a date in the future on the form. Just replace your view and field where the XX’s are.&nbsp;

To restrict to only dates in the future, simply change maxDate: 0 to minDate: 0

---

<div class="post-metadata">

**Author:** ![BartvanBeu70192](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@BartvanBeu70192](https://forums.knack.com/u/BartvanBeu70192)\
**Post date:** [October 23, 2015, 7:50am UTC](https://forums.knack.com/t/restricting-dates-on-calendar/10312/2 "2015-10-23T07:50:47Z")

</div>

Does this work ?

```
$.datepicker.setDefaults({ minDate:'0' });
```

Here's a good tutorial on DatePicker

[https://www.script-tutorials.com/datepicker-jquery-ui/](https://www.script-tutorials.com/datepicker-jquery-ui/)

&nbsp;

---

<div class="post-metadata">

**Author:** ![SergeDenis46033](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@SergeDenis46033](https://forums.knack.com/u/SergeDenis46033)\
**Post date:** [October 16, 2015, 3:38am UTC](https://forums.knack.com/t/restricting-dates-on-calendar/10312/3 "2015-10-16T03:38:38Z")

</div>

Hello,

I tried to use this code to prevent users to pick date in the past but it does not seem to work for me. I did replace maxDate = 0 by minDate=0. Please advice. Thank you!

---

<div class="post-metadata">

**Author:** ![BradStevens](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/bradstevens/32/140_2.png) [@BradStevens](https://forums.knack.com/u/BradStevens)\
**Post date:** [March 2, 2015, 7:43am UTC](https://forums.knack.com/t/restricting-dates-on-calendar/10312/4 "2015-03-02T07:43:33Z")

</div>

Hey great, thanks for sharing Craig!
