-1

Am trying to limit the date to today's date and a day before

<label for="sel1">Select Date:</label>
<input type="date" value="<?php echo date("Y-m-d");?>" min=? name="date">

</select>
S.M Talha
  • 59
  • 1
  • 10

2 Answers2

1

You can use date time objects and modify. This is my personally preferred way (though there are others).

<?php 
$min = new DateTime();
$min->modify("-1 days");
$max = new DateTime();
?>

<label for="sel1">Select Date:</label>
<input type="date" value="<?php echo date("Y-m-d");?>" min=<?=$min->format("Y-m-d")?> max=<?=$max->format("Y-m-d")?> name="date">

</select>
apokryfos
  • 38,771
  • 9
  • 70
  • 114
0

You can limit the dates using the min and max attributes on the input. If you want to do this automatically with a bit of php you could try something similar to the following:

<?php
$yesterday = new DateTime();
$yesterday->sub(new DateInterval('P1D')); // go back one day
echo $yesterday->format('Y-m-d') . "\n";
?>

<label for="sel1">Select Date:</label>
<input type="date" value="<?php echo date("Y-m-d");?>" min="<?php echo $yesterday;?>" max="<?php echo date("Y-m-d");?>" name="date">

</select>
BottyZ
  • 145
  • 2
  • 10