Ask Your Question
0

How can I limit the selection of future dates in the HTML5 date input?

asked 2021-05-25 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-01-31 00:00:00 +0000

bukephalos gravatar image

You can use the "min" and "max" attributes to limit the selection of future dates in the HTML5 date input.

The "min" attribute sets the minimum date that can be selected while the "max" attribute sets the maximum date that can be selected.

You can set the "min" attribute to today's date to prevent users from selecting a date in the past. For example:

<input type="date" min="<?php echo date('Y-m-d'); ?>">

You can also set the "max" attribute to a specific date in the future to prevent users from selecting dates beyond that point. For example:

<input type="date" max="2023-12-31">

You can use both attributes together to limit the selection of dates within a specific range. For example:

<input type="date" min="<?php echo date('Y-m-d'); ?>" max="2023-12-31">

Note: The "min" and "max" attributes are not supported in some older browsers.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-05-25 11:00:00 +0000

Seen: 15 times

Last updated: Jan 31 '23