# Perspective: restrict DateTime input till current date only

**URL:** <https://forum.inductiveautomation.com/t/perspective-restrict-datetime-input-till-current-date-only/38116>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 27, 2020, 5:03am UTC](https://forum.inductiveautomation.com/t/perspective-restrict-datetime-input-till-current-date-only/38116 "2020-08-27T05:03:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yash.bhan](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yash.bhan](https://forum.inductiveautomation.com/u/yash.bhan)\
**Post date:** [August 27, 2020, 5:03am UTC](https://forum.inductiveautomation.com/t/perspective-restrict-datetime-input-till-current-date-only/38116/1 "2020-08-27T05:03:40Z")

</div>

Hi

Is there a way to restrict the date choices in DateTime input component in perspective to not allow to select future dates, only dates till the current date should be allowed to select on the calendar and the future dates should be grayed-out/disabled.

Thanks  
Yash Bhan

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 27, 2020, 2:46pm UTC](https://forum.inductiveautomation.com/t/perspective-restrict-datetime-input-till-current-date-only/38116/2 "2020-08-27T14:46:29Z")

</div>

I put this in a change script on the value property of the DateTimePicker. It doesn’t gray out future dates, but it does disallow choosing dates in the future. You can tweak it to behave exactly how you want it to.

```auto
now = system.date.now()
	if system.date.isAfter(currentValue.value,now) and origin!='Script':
		try:
			if system.date.isAfter(previousValue.value,now):
				self.props.value = now
			else:
				self.props.value = previousValue.value
		except AttributeError:
			self.props.value = now

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [August 27, 2020, 4:08pm UTC](https://forum.inductiveautomation.com/t/perspective-restrict-datetime-input-till-current-date-only/38116/3 "2020-08-27T16:08:38Z")

</div>

Both Date Picker components have a minDate and a maxDate property to define available dates for the picker. It doesn’t truly “gray-out” the unavailable dates, but it does prevent them from being selected and it applies a “restricted” cursor when hovering over restricted dates. Months and years in the dropdown ARE grayed-out.

 ![Screen Shot 2020-08-27 at 9.06.45AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/7/17da428ac209279e3661ad8c4c04a9ab9dd960e6.png)  
This feature was only introduced fairly recently (8.0.13).

---

<div class="post-metadata">

**Author:** ![yash.bhan](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yash.bhan](https://forum.inductiveautomation.com/u/yash.bhan)\
**Post date:** [August 27, 2020, 5:48pm UTC](https://forum.inductiveautomation.com/t/perspective-restrict-datetime-input-till-current-date-only/38116/4 "2020-08-27T17:48:01Z")

</div>

Thanks a lot! Will try this

---

<div class="post-metadata">

**Author:** ![yash.bhan](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yash.bhan](https://forum.inductiveautomation.com/u/yash.bhan)\
**Post date:** [August 27, 2020, 5:49pm UTC](https://forum.inductiveautomation.com/t/perspective-restrict-datetime-input-till-current-date-only/38116/5 "2020-08-27T17:49:00Z")

</div>

Ahaa, we are on 8.0.12, hence I couldn’t see the option. Thanks for the info!

---

<div class="post-metadata">

**Author:** ![Anders\_Liedman](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Anders\_Liedman](https://forum.inductiveautomation.com/u/Anders_Liedman)\
**Post date:** [April 12, 2024, 11:33am UTC](https://forum.inductiveautomation.com/t/perspective-restrict-datetime-input-till-current-date-only/38116/6 "2024-04-12T11:33:56Z")

</div>

Placed a onActionPerformed event for the datepicker. add a script action with  
now=system.date.now()  
self.props.maxDate=now

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 12, 2024, 11:49am UTC](https://forum.inductiveautomation.com/t/perspective-restrict-datetime-input-till-current-date-only/38116/7 "2024-04-12T11:49:52Z")

</div>

There's no need for a script, Anders. A binding will do it with less overhead and can update constantly. In addition, your script seems to update maxDate _after_ the user has chosen the date.

Create an Expression Binding on maxDate:  
`now(5000)`  
This will update every 5 s.
