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>
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>
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>
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>