Ver Mensaje Individual
  #4  
Antiguo 25-11-2022
giantonti1801 giantonti1801 is offline
Miembro
 
Registrado: oct 2022
Posts: 143
Reputación: 2
giantonti1801 Va por buen camino
Cita:
Empezado por Neftali [Germán.Estévez] Ver Mensaje
En este caso para obtener los datos entre dos fechas (desde...hasta) como comentas debes usar el operador BETWEEN e indicar las dos fechas.
Si segun la Base de Datos que utilices no puedes usarlo deberás usar algo como:

Código Delphi [-]
WHERE (FechaCre >= fecha1) and (FechaCre <= fecha2)



Seguramente es por eso y al estar usando un =, sólo te retornaría registros que coincidan exactamente con la fecha y hora.
Lo primero, yo te aconsejaría utilizar parámetros en la consulta, eso te evita todos los problemas relacionados con el formato del campo.

Código Delphi [-]
  ADOQuery1.SQL.Add('where FechaCre where Fecha between :fecha1 and :fecha2)');
  ADOQuery1.Parameters.ParamByName('fecha1').Value := DateTimePicker1.Date;
  ADOQuery1.Parameters.ParamByName('fecha2').Value := DateTimePicker2.Date;

Lo segundo es que resuelvas el tema de fecha o FechayHora en los valores. Asegúrate de enviar sólo valores de fecha (sin hora).
Gracias por la ayuda, fijate algo curioso que esta sucediendo.

Código Delphi [-]
procedure TFormConsulta.DateTimePicker1Change(Sender: TObject);
begin
   LabelDesde.Caption := DateToStr(DateTimePicker1.Date);
   ADOQuery1.Close;
   ADOQuery1.SQL.Clear;
   ADOQuery1.SQL.Add('Select * from Tiket');
   ADOQuery1.SQL.Add('where FechaCre between :Fecha1 and :Fecha2');
   ADOQuery1.Parameters.ParamByName('Fecha1').Value := DateTimePicker1.Date;
   ADOQuery1.Parameters.ParamByName('Fecha2').Value := DateTimePicker2.Date;
   ADOQuery1.Open;
end;

procedure TFormConsulta.DateTimePicker2Change(Sender: TObject);
begin
  LabelHasta.Caption := DateToStr(DateTimePicker2.Date);
  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('Select * from Tiket');
  ADOQuery1.SQL.Add('where FechaCre between :Fecha1 and :Fecha2');
  ADOQuery1.Parameters.ParamByName('Fecha1').Value := DateTimePicker1.Date;
  ADOQuery1.Parameters.ParamByName('Fecha2').Value := DateTimePicker2.Date;
  ADOQuery1.Open;
 end;


Código SQL [-]
2022-11-24 22:53:00.000
2022-11-25 21:58:00.000
2022-11-26 21:58:00.000
2022-11-27 21:58:00.000
2022-11-28 21:58:00.000

Haciéndolo de esta forma cuando le pongo la fecha desde 24-11-2022 hasta el 24-11-2022 debería mostrarme la operaciones en esta fecha pero no lo hace, es decir no me retorna ningún valor y así siguientemente si lo hago con las otras fecha del 25 hasta el 25 y del 26 hasta el 26. pero si pongo desde 24 hasta el 25 me muestra las operaciones del día 24 y si lo hago desde 25 hasta 26 me muestra la operaciones del día 25.
Pero si lo hago desde 24-11-2022 hasta el 25-11-2022
Responder Con Cita