Pareces nuevo por aquí. Si quieres participar, ¡pulsa uno de estos botones!
<?= date_field_tag('fecha', 'start_year: 1800', 'end_year: 2050', 'use_month_num: true', 'order: d-m-Y'); ?>
function date_field_tag($name){ $config = Config::read('core.ini'); $value = get_value_from_action($name); $name = get_params(func_get_args()); if(!$name[0]) $name[0] = $name['id']; if(!$name['name']) $name['name'] = $name[0]; if(!$value) $value = $name['value']; if($value){ $ano = substr($value, 0, 4); $mes = substr($value, 5, 2); $dia = substr($value, 8, 2); } else { $ano = date('Y'); $mes = date('m'); $dia = date('d'); } $start_year = (isset($name['start_year'])) ? (int)$name['start_year'] : 1900; $end_year = (isset($name['end_year'])) ? (int)$name['end_year'] : date('Y'); if($end_year < $start_year){ $end_year = $start_year; } $meses = array( "01" => "Ene", "02" => "Feb", "03" => "Mar", "04" => "Abr", "05" => "May", "06" => "Jun", "07" => "Jul", "08" => "Ago", "09" => "Sep", "10" => "Oct", "11" => "Nov", "12" => "Dic", ); $select_month = "<select name='{$name[0]}_month' id='{$name[0]}_month' onchange=\"$('{$name[0]}').value = $('{$name[0]}_year').options[$('{$name[0]}_year').selectedIndex].value+'-'+$('{$name[0]}_month').options[$('{$name[0]}_month').selectedIndex].value+'-'+$('{$name[0]}_day').options[$('{$name[0]}_day').selectedIndex].value\" >"; if(isset($name['use_month_num'])){ foreach($meses as $numero_mes => $nombre_mes){ if($numero_mes==$mes){ $select_month.="<option value='$numero_mes' selected='selected'>$numero_mes</option>\n"; } else { $select_month.="<option value='$numero_mes'>$numero_mes</option>\n"; } } } else { foreach($meses as $numero_mes => $nombre_mes){ if($numero_mes==$mes){ $select_month.="<option value='$numero_mes' selected='selected'>$nombre_mes</option>\n"; } else { $select_month.="<option value='$numero_mes'>$nombre_mes</option>\n"; } } } $select_month.="</select>&nbsp;"; $select_day ="<select name='{$name[0]}_day' id='{$name[0]}_day' onchange=\"$('{$name[0]}').value = $('{$name[0]}_year').options[$('{$name[0]}_year').selectedIndex].value+'-'+$('{$name[0]}_month').options[$('{$name[0]}_month').selectedIndex].value+'-'+$('{$name[0]}_day').options[$('{$name[0]}_day').selectedIndex].value\">"; for($i=1;$i<=31;$i++){ $n = sprintf("%02s", $i); if($n==$dia){ $select_day.="<option value='$n' selected='selected'>$n</option>\n"; } else { $select_day.="<option value='$n'>$n\n"; } } $select_day.='</select>&nbsp;'; $select_year ="<select name='{$name[0]}_year' id='{$name[0]}_year' onchange=\"$('{$name[0]}').value = $('{$name[0]}_year').options[$('{$name[0]}_year').selectedIndex].value+'-'+$('{$name[0]}_month').options[$('{$name[0]}_month').selectedIndex].value+'-'+$('{$name[0]}_day').options[$('{$name[0]}_day').selectedIndex].value\" >"; for($i=$end_year;$i>=$start_year;$i--){ if($i==$ano){ $select_year.="<option value='$i' selected='selected'>$i\n"; } else { $select_year.="<option value='$i'>$i</option>\n"; } } $select_year.='</select>'; if(isset($name['order'])){ if($name['order']=='Y-m-d'){ $code = $select_year.$select_month.$select_day; } elseif($name['order']=='d-m-Y'){ $code = $select_day.$select_month.$select_year; } else { $code = $select_month.$select_day.$select_year; } } else { $code = $select_month.$select_day.$select_year; } $code.="<input type='hidden' id='{$name[0]}' name='{$name[0]}' value='$value'>"; return $code; }
Comentarios
Ya lo subi al svn.
Saludos.