Skip to content
Advertisement

Php Disabling past days in datetime_local picker

I am making an event calendar. I am currently looking for ways to disable the previous dates on datetime_local and the minimum date and time is the current. Are there other ways?

JavaScript

Advertisement

Answer

If you look at the definition for datetime-local, you’ll see it has a min and max attribute. You can use PHP to set the min time:

JavaScript

Note that this will not always work the way you want

Because of the limited browser support for datetime-local, and the variations in how the inputs work, it may currently still be best to use a framework or library to present these, or to use a custom input of your own. Another option is to use separate date and time inputs, each of which is more widely supported than datetime-local.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement