Shakil Ahmed
Shakil Ahmed

Reputation: 51

How to set input field's max date from current date

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

I want users to select a date between current date to next 7 days. This input min disables past dates from current date . Now how can I set the max limit next 7 days from current date?

Upvotes: 1

Views: 6535

Answers (2)

Professor Abronsius
Professor Abronsius

Reputation: 33813

You can try adding the max attribute to the input but be aware that this can be modified in the browser.

<input type="date" name="date" min="<?=date('Y-m-d');?>" max="<?=date('Y-m-d',strtotime('now +1 week'));?>" />

Upvotes: 3

BoCoder24
BoCoder24

Reputation: 1

You could try by adding:

max=
 <?php
     echo date('Y-m-d', strtotime('+7 days'));
 ?>

?

Increase days to php current Date()

Upvotes: 0

Related Questions