lena
lena

Reputation: 143

How to set the datepicker in html5 selection from current date onwards?

I have used the date of html5

<input type="date" name="date" id="datee" placeholder="Date" required>

I want to set here selection from current date onwards. How to do that ? Can anyone say how to do this ?

Upvotes: 1

Views: 117

Answers (2)

heheh
heheh

Reputation: 11

Here's how:

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

<p>For example, we will set the min date manually to "2017-11-24"</p>

<input type="date" min="2017-11-24">

You can also set max value.

Upvotes: 1

Navnit
Navnit

Reputation: 327

You can use pure javascript as html5 input does not provide any other way to add the current date unless you specify with the format dd-mm-yyyy.

So here is the javascript code that will fill the input with the current date.

<script>
 document.getElementById('datee').valueAsDate = new Date();
</script>

Hope this helps

Upvotes: 1

Related Questions