diff --git a/include/datetime.php b/include/datetime.php
index f7be5bdb1..67c4f42fa 100644
--- a/include/datetime.php
+++ b/include/datetime.php
@@ -108,9 +108,17 @@ function datesel($pre,$ymin,$ymax,$allow_blank,$y,$m,$d) {
$o .= "";
}
- for($x = $ymax; $x >= $ymin; $x --) {
- $sel = (($x == $y) ? " selected=\"selected\" " : "");
- $o .= "";
+ if($ymax > $ymin) {
+ for($x = $ymax; $x >= $ymin; $x --) {
+ $sel = (($x == $y) ? " selected=\"selected\" " : "");
+ $o .= "";
+ }
+ }
+ else {
+ for($x = $ymax; $x <= $ymin; $x ++) {
+ $sel = (($x == $y) ? " selected=\"selected\" " : "");
+ $o .= "";
+ }
}
$o .= "