two selects example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="en" />
<title>Test</title>
</head>
<body>
<form>
<fieldset>
<legend></legend>
<label for="date">date : </label>
<select id="date" name="date" title="Peek a date">
<?php
$beg = new DateTime();
$end = new DateTime();
$end->modify("+6 years");
while($beg->format("U") <= $end->format("U")) {
$d = $beg->format("d/m/Y");
echo "<option value='" . $d . "'" . (date("d/m/Y") == $d ? " selected='selected'" : "") . ">" . $d . "</option>\n";
$beg->modify("+1 day");
}
?>
</select>
<label for="time">time : </label>
<select id="time" name="time" title="Peek a time">
<?php
foreach(range(0, 24) as $h) {
foreach(range(0, 59) as $m) {
$t = sprintf("%02d:%02d", $h, $m);
echo "<option value='" . $t . "'" . (date("H:i") == $t ? " selected='selected'" : "") . ">" . $t . "</option>\n";
}
}
?>
</select>
</body>
</html>
or with jQuery UI datepicker (more friendly IMHO):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="en" />
<script type="text/javascript" src="includes/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="includes/js/jquery-ui-1.7.2.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="includes/js/themes/ui-lightness/jquery-ui-1.7.2.custom.css" media="screen, print" />
<script type="text/javascript">
$(document).ready(function() {
var d = new Date();
$("#date").datepicker({
minDate: d,
maxDate: new Date(d.getFullYear() + 6, d.getMonth(), d.getDay()),
dateFormat: "dd/mm/yy",
mandatory: true,
changeFirstDay: false,
changeYear: true,
showStatus: true,
showOn: "both",
buttonImage: "images/calendar.gif",
buttonImageOnly: true
}).addClass("embed");
});
</script>
</head>
<body>
<form>
<fieldset>
<legend></legend>
<label for="date">date : </label>
<input type="text" name="date" id="date" />
<label for="time">time : </label>
<select id="time" name="time" title="Peek a time">
<?php
foreach(range(0, 24) as $h) {
foreach(range(0, 59) as $m) {
$t = sprintf("%02d:%02d", $h, $m);
echo "<option value='" . $t . "'" . (date("H:i") == $t ? " selected='selected'" : "") . ">" . $t . "</option>\n";
}
}
?>
</select>
</body>
</html>