![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
26/03/2008, 12:58
|
![Avatar de ranceis](http://static.forosdelweb.com/customavatars/avatar152711_1.gif) | | | Fecha de Ingreso: septiembre-2006
Mensajes: 42
Antigüedad: 18 años, 4 meses Puntos: 0 | |
Re: Capturar y validar fecha Te dejo un codigo que hice, espero y sea lo que buscas.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>
<body>
<?php
$fechaactual=date("d/m/Y");
$dia=$_POST['dia'];
$mes=$_POST['mes'];
$diaactual=substr($fechaactual,0,2);
$mesactual=substr($fechaactual,3,2);
$anioactual=substr($fechaactual,6,4);
if (isset ($_POST['enviar'])){
if(eregi("^[[:digit:]]{0,2}$", $dia) ){
$d=true;
$Dia_=$dia;
}else{
//$dia="";
$Dia_=$diaactual;
}
if(eregi("^[[:digit:]]{0,2}$", $mes) ){
//$efecha=true;
$m=true;
$Mes_=$mes;
$Mm=$mesactual+1;
}else{
//$mes="";
$Mes_=$mesactual;
}
if($mes==$Mm){
$m1=true;
}
if($mes==$mesactual){
$ma=true;
if($ma==true){
if($dia>=$diaactual){
$m1=true;
}
}
}
if ($m1==true){
if(@checkdate($mes,$dia,$anioactual)){ //checa que la fecha sea una valida.
$formato=true;
$fechainicioP=$dia."-".$mes."-".$anioactual;
$fechainiciopub=$anioactual."-".$mes."-".$dia;
//$fechaconclusion=$dia+$DuracionVentaart;
//echo $fechaconclusion;
}else{
$efecha=true;
}
}else{
$efecha=true;
}
echo $efecha;
}
//////////////////////////////////
?>
<form id="form1" name="form1" method="post" action="">
<table width="557" border="0">
<tr>
<td><strong>* Fecha </strong></td>
<td><label for="select">Dia
<input name="dia" type="text" id="dia" size="1" value="<? echo $Dia_; ?>" maxlength="2" />
Mes
<input name="mes" type="text" id="mes" size="1" value="<? echo $Mes_; ?>" maxlength="2" />
año
<input name="anio" id="anio" readonly="readonly" value="<? echo $anioactual; ?>" size="2" maxlength="4" />
<?
if ($efecha==true){
echo"<font color=\"#f0000\" size=\"1\">favor de introducir una fecha valida </font>";
}
?>
</label>
<label>
<input name="enviar" type="submit" id="enviar" value="Enviar" />
</label>
</td>
</tr>
</table>
</form>
</body>
</html> |