Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   SQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=6)
-   -   Filtrado en Sql por fechas (https://www.clubdelphi.com/foros/showthread.php?t=88403)

ecfisa 02-06-2015 03:57:09

Hola Daniel.

Creo que podrías fijar el Edit en blanco, el primer DateTimePicker en la menor fecha deseada y el segundo en la actual. De esa manera, si no realiza ningún cambio en los valores obtiene el listado sin filtro, de otro modo se filtrará por las opciónes que haya configurado.

Ejemplo:
Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
begin
  dtpDesde.Date := 1;      // 31/12/1899
  dtpHasta.Date := Date; // fecha de hoy
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT TITULO, DESCRIPCION_PRODUCTO, PRECIO_BASE, FECHA_INICIO, FECHA_FIN, FOTO');
    SQL.Add('FROM SUBASTA_PROD');
    SQL.Add('WHERE TITULO LIKE :TIT  AND');
    SQL.Add('FECHA_INICIO >= :INI AND FECHA_FIN <= :FIN');
    Parameters.ParamByName('TIT').Value := '%' + Edit1.Text +'%';
    Parameters.ParamByName('INI').Value := dtpDesde.DateTime;
    Parameters.ParamByName('FIN').Value := dtpHasta.DateTime;
    Open;
  end;
end;
Como la "fecha desde" del ejemplo usé el big bang delphiano, pero te convendría fijar el DateTimePicker(desde) a la fecha de inicio de carga de datos en la tabla "SUBASTA_PROD".

Saludos :)


La franja horaria es GMT +2. Ahora son las 13:11:18.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi