C sharp - c# comparar una feha de inicio y una fecha final

 
Vista:

c# comparar una feha de inicio y una fecha final

Publicado por Fco Navarro (11 intervenciones) el 14/08/2018 16:30:29
c# comparar una feha de inicio y una fecha final y que se pueda agregar en sql server
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

c# comparar una feha de inicio y una fecha final

Publicado por miguelZ (5 intervenciones) el 14/08/2018 17:06:00
Pero en si cual es tu duda,

que tanto llevas de codigo y en donde te perdiste?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

c# comparar una feha de inicio y una fecha final

Publicado por Fco Navarro (11 intervenciones) el 14/08/2018 18:50:44
esto tengo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private void button1_Click(object sender, EventArgs e)
{
 
    SqlCommand comando = new SqlCommand ( "INSERT INTO fechaprueba(correctivo,hora_analisis,numero,fecha_registro,fecha_fin) " + "VALUES(@CO, @HA, @NU, @FR,@FF)", conexcion);
 
 
    comando.Parameters.AddWithValue("@CO", txtcorre.Text);
    comando.Parameters.AddWithValue("@HA", txtha.Text);
    comando.Parameters.AddWithValue("@NU", txtnu.Text);
    comando.Parameters.AddWithValue("@FR", fechainicial.Value);
    comando.Parameters.AddWithValue("@FF", fechafin.Value);
 
    conexcion.Open();
    comando.ExecuteNonQuery();
    conexcion.Close();
    MessageBox.Show("SI");
}
ya tengo como insetarlo pero quiero comparar la fechainicial y la fechafin se comparen y salga un mensaje diciendo que llego a esa fecha las fecha son dateTimePicker
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

c# comparar una feha de inicio y una fecha final

Publicado por miguelZ (5 intervenciones) el 15/08/2018 17:29:15
ok, primero para claridad en tu codigo debes separar los metodos de acuerdo a su funcionalidad


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
///pseudo codigo --puede contener errores de sintaxis solo seguir la idea.
 
 
 private void button1_Click(object sender, EventArgs e)
{
    //validando fechas si fecha posterior es antes que fecha fin no se hace nada
 
  if( ! validarFechas(fechainicial.Value, fechainicial.Value))
{
    Messagebox.Show("La fecha final debe ser posterior a la fecha inicial");
 
   return;
}
 
 insertarRegistro()
 
}
 
private void insertarRegistro()
{
 
 SqlCommand comando = new SqlCommand ( "INSERT INTO fechaprueba(correctivo,hora_analisis,numero,fecha_registro,fecha_fin) " + "VALUES(@CO, @HA, @NU, @FR,@FF)", conexcion);
 
 
    comando.Parameters.AddWithValue("@CO", txtcorre.Text);
    comando.Parameters.AddWithValue("@HA", txtha.Text);
    comando.Parameters.AddWithValue("@NU", txtnu.Text);
    comando.Parameters.AddWithValue("@FR", fechainicial.Value);
    comando.Parameters.AddWithValue("@FF", fechafin.Value);
 
    conexcion.Open();
    comando.ExecuteNonQuery();
    conexcion.Close();
    MessageBox.Show("SI");
 
 
}
 
//validando que la fecha final sea mayor a la fecha inicial
private bool ValidarFechas(string fechaInicial, string FechaFinal)
{
      DateTime fechaInicio= new DateTime(fechaIncial);
      DateTime fechaFin= new DateTime(fechaFinal);
 
      int result = DateTime.Compare(fechaInicio,fechaFin);
      string relationship;
 
      if (result < 0)//fechaInicio es anterior  a fecha fin
         return true;
 
      else if (result == 0) //ambas son las mismas fechas
       return false;
      else          //fecha fin es menor a fecha inicial
       return false;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar