Ver Mensaje Individual
  #4 (permalink)  
Antiguo 12/04/2004, 09:28
Avatar de RootK
RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 22 años, 3 meses
Puntos: 50
Cita:
defines una variable de tipo fecha y otra de respuesta y realizamos la validacion
Eso puede funcionar pero dependiendo de como tengas configurado el idioma de tu server.. ya que si lo tienes en ingles la funcion Cdate tomará el formato mm/dd/YYYY y si lo pones de la manera dd/mm/yyyy entonces indicará que no es una fecha válida... ,

De todas formas puedes crear una funcion para que se te haga mas facil pasar los parámetros siempre en formato dd/mm/yyyy

Ejemplo:

Vb.Net
Cita:
Private Function IsDateValid(ByVal d As Integer, ByVal m As Integer, ByVal y As Integer) As Boolean

'y = year
'm = month
'd = day
Try
Dim _date As DateTime = New DateTime(y, m, d)
Return True
Catch ex As ArgumentOutOfRangeException
Return False
End Try

End Function
Y para llamarla

Cita:
dim d as integer = Cint(textbox1.text)
dim m as integer = Cint(textbox2.text)
dim y as integer = Cint(textbox3.text) 'En formato yyyy = 2004

If IsDateValid (d, m, y) Then
Response.Write("Fecha Valida")
Else
Response.Write("Fecha Inválida")
End If
C#
Cita:
private bool IsDateValid (int d, int m, int y)
{
try
{
DateTime date = new DateTime (y, m, d);
return true;
}
catch (ArgumentOutOfRangeException)
{
return false;
}
}
Y para llamarla:

Cita:
int d = Convert.ToInt32(TextBox1.Text);
int m = Convert.ToInt32(TextBox2.Text);
int y = Convert.ToInt32(TextBox3.Text);

if (IsDateValid (d,m,y))
Response.Write("Fecha Válida");
else
Response.Write("Fecha Inválida");
Saludos y espero te sirva el ejemplo