Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Firebird e Interbase (https://www.clubdelphi.com/foros/forumdisplay.php?f=19)
-   -   Locate a una tipo date o time (https://www.clubdelphi.com/foros/showthread.php?t=16396)

RONPABLO 26-11-2004 04:58:58

Locate a una tipo date o time
 
Hola, de antemano gracias por la ayuda que me puedan prestar.
Tengo una base de datos en firebird 1.5, y una aplicacion hecha en Delphi 6, resulta que he tenido problemas al hacer locate sobre variables de tipo time o date. Para solucionar esto realizo combersiones de tipo, pero me parese algo redundante. por ejemplo tengo un MonthCalendar el caul quiero que al hacer click en una fecha determinada me localice o gurde la fecha si no existe, pero parese que al hacer click en una fecha el valor date del MonthCalendar no es un TDate sino algo asi como un TDatatime entonces captura la fecha y algo mas (hora) ya que al hacer el locate no encuentra la fecha, pero si hago un datetostr e igualo a una variable de tipo string y luego en el locate doy strtodate a esta variable funciona bien el locate.
Pero me gustaria no tener que realizar la combersion de tipos, si me puede orientar le agradeceria muho.

defcon1_es 26-11-2004 09:11:56

Hola,
puedes usar la función Date() para olvidarte de la hora del MonthCalendar:

En la ayuda de Delphi:
Código:

function Date: TDateTime;
 
Description
 
Use Date to obtain the current local date as a TDateTime value. The time portion of the value is 0

Ejemplo:
Código Delphi [-]
DataSet.Locate('FECHA', Date(MonthCalendar.Date), []);

pacogarcia 26-11-2004 09:42:09

Saludos.


La funcion "date" devuelve la fecha actual.

Yo utilizo esta funcion para extraer la fecha:

Código Delphi [-]
function ExtraerFecha(fechayhora :TDateTime) : TDateTime;
var year,Month,Day : word;
begin
    DecodeDate( fechayhora, Year, Month, Day);
    result := EncodeDate(Year, Month, Day);
end;
Espero que te sirva.

Un saludo.

defcon1_es 26-11-2004 12:11:00

Cita:

Empezado por pacogarcia
La funcion "date" devuelve la fecha actual.

Tienes toda la razón del mundo... eso me pasa por ir deprisa.

Quería decir la función DateOf()

Código Delphi [-]
 
DataSet.Locate('FECHA', DateOf(MonthCalendar.Date), []);

Salu2.

RONPABLO 27-11-2004 01:35:54

Muchas gracias
 
Ok gracias por sus respuestas si me dio con el "dateof"

Mick 27-11-2004 18:43:00

Cita:

Empezado por pacogarcia
Saludos.
Yo utilizo esta funcion para extraer la fecha:

Código Delphi [-]
function ExtraerFecha(fechayhora :TDateTime) : TDateTime;
var year,Month,Day : word;
begin
    DecodeDate( fechayhora, Year, Month, Day);
    result := EncodeDate(Year, Month, Day);
end;

Yo sustituiria esa funcion por:

Fecha:= Int(FechaYHora)

que es bastante mas rapido que decodificar y codificar un Datetime.

Saludos

defcon1_es 29-11-2004 09:49:04

Hola, mira lo que hace la función DateOf
Código Delphi [-]
function DateOf(const AValue: TDateTime): TDateTime;
begin
  Result := Trunc(AValue);
end;


La franja horaria es GMT +2. Ahora son las 20:47:34.

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