Hvis jeg var dig, ville jeg nok lave nogle selects, så der er rimelig sikkerhed for datoformatet. Det kunne (helt skrabet) se sådan ud:
<?php
if (!empty($_POST)) {
if (isset($_POST['contxt']) && $_POST['contxt']=='doDaShit') {
$stamp = mktime($_POST['hour'], $_POST['min'], 0, $_POST['month'], $_POST['day'], $_POST['year']);
echo date('d.m.Y H:i:s', $stamp);
}
}
class TimeInput {
private $thisYear;
public function __construct() {
$this->thisYear = date("Y", time());
}
public function write_year() {
$a = array();
for ($i=$this->thisYear-100; $i<$this->thisYear; $i++) {
$a[] = '<option value="'.$i.'">'.$i.'</option>';
}
return '<select name="year"><option value="-1">åååå</option>'.implode('', $a).'</select>';
}
public function write_month() {
$a = array();
for ($i=1; $i<13; $i++) {
$j = $i>9 ? $i : '0'.$i;
$a[] = '<option value="'.$i.'">'.$j.'</option>';
}
return '<select name="month"><option value="-1">mm</option>'.implode('', $a).'</select>';
}
public function write_day() {
$a = array();
for ($i=1; $i<32; $i++) {
$a[] = '<option value="'.$i.'">'.$i.'</option>';
}
return '<select name="day"><option value="-1">dd</option>'.implode('', $a).'</select>';
}
public function write_hour() {
$a = array();
for ($i=0; $i<24; $i++) {
$j = $i>9 ? $i : '0'.$i;
$a[] = '<option value="'.$i.'">'.$j.'</option>';
}
return '<select name="hour"><option value="-1">tt</option>'.implode('', $a).'</select>';
}
public function write_min() {
$a = array();
for ($i=0; $i<60; $i++) {
$j = $i>9 ? $i : '0'.$i;
$a[] = '<option value="'.$i.'">'.$j.'</option>';
}
return '<select name="min"><option value="-1">mm</option>'.implode('', $a).'</select>';
}
}
$timeInput = new TimeInput();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "
http://www.w3.org/TR/html4/strict.dtd"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post">
<p><input name="contxt" value="doDaShit" type="hidden">
Tid: <?php echo $timeInput->write_day(), ' ', $timeInput->write_month(), ' ', $timeInput->write_year(), ' ', $timeInput->write_hour(), ' ', $timeInput->write_min() ?></p>
<p><button type="submit">Send</button></p>
</form>
</body>
</html>
Så kan du altid sætte nogle værdier som 'selected' - alt efter i hvilket område, man forventer, brugerne vil vælge f.eks. et årstal.