0

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?

<div class="form-group">
<label for="datetime_start" class="control-label">DateTime Start:</label>
<input type="datetime-local" class="form-control" name="datetime_start" id="datetime_start">
</div>
aynber
  • 22,380
  • 8
  • 50
  • 63
Coco
  • 3
  • 5
  • "*Are there other ways?*" Ways other than *what*? You don't seem to have any functionality to "*disable the previous dates*" in the snippet above. How is this at all related to [tag:php]? – esqew Oct 08 '21 at 17:50
  • Does this answer your question? [How to I set min and max value for Input with type='datetime-local'?](https://stackoverflow.com/questions/44585148/how-to-i-set-min-and-max-value-for-input-with-type-datetime-local) – esqew Oct 08 '21 at 17:51

1 Answers1

0

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:

<input type="datetime-local" 
     class="form-control" 
     name="datetime_start" 
     id="datetime_start" 
     min="<?php echo date('Y-m-d\TH:i') ?>"
>

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.

aynber
  • 22,380
  • 8
  • 50
  • 63
  • How about when the min is the current time and date so that i will not repeatedly change the previous dates? – Coco Oct 08 '21 at 17:58
  • `date('Y-m-d\TH:i')` is the current date/time as of the moment the page loads. – aynber Oct 08 '21 at 18:03