Prevent future dates

  • 0
  • 1
  • Question
  • Updated 5 months ago
  • Answered
Can I prevent future dates in a date field? I need to only allow the user to select the current day or before.
Photo of Shontay

Shontay

  • 490 Points 250 badge 2x thumb

Posted 2 years ago

  • 0
  • 1
You can use a form rule to prevent the record from being saved if the date is after the current date (see image below).

Adding a form rule that will change the date to the current date if the user tries to set it for a future date works sometimes but not every time. The rule to prevent it from being saved is the better way.

Note that this won't prevent users from entering a future date using grid edit, another form, or the API.

Depending on your use case, you could also create a second date field - a formula date field - to make sure the date is never later than the current date. Users could enter any date they want in the first date field, using any form, grid edit, or the API - and the value of the formula  date field would either be the date chosen by the user or the date the record was created, whichever is earlier.

Phillip Dennis

(Edited)
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 28,004 Points 20k badge 2x thumb
QuickBase uses the jQueryUI datepicker and the datepicker can be configured through script to allow or disallow dates that meet certain criteria.

See these pasties and links to old forum posts and demos:

Formula for date field to display only first day of each week?
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=257

Can I use a date - formula field to force users to input only the current date or a past one, no future date
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=447

Is there a way to only allow certain dates to be selected in a date field
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=513
Photo of Tyler Parker

Tyler Parker

  • 810 Points 500 badge 2x thumb
Hey Dan, if I wanted to force users to input only the current date or a future date, no past date, would I change the "maxDate" here to "minDate"? 

$("#_fid_6").datepicker("option", {
  maxDate: "0"
});
(Edited)
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 27,994 Points 20k badge 2x thumb
I think so. See:

jQueryUI minDate Optioin
http://api.jqueryui.com/datepicker/#option-minDate
Photo of Tyler Parker

Tyler Parker

  • 810 Points 500 badge 2x thumb
Awesome, thanks for the link