How to read only the FormatDataTime numbers

-1

I needed to know the current time of the computer and compare it with values in the database, for example:

'agenda.hora >= "' + formatdatatime('hh:ss',now) + ";

It turns out that both the bank and the format will return a string, the bank I can convert to integer, but I do not know how to convert the result of FormatDataTime .

    
asked by anonymous 28.09.2017 / 15:11

3 answers

1

Using the DateUtils unit, you have access to functions such as HourOf (TDatetime). You can do

valorHora:=HourOf(now);

and use this value as an int

    
28.09.2017 / 15:20
1

I'll give you an example of two ways to do this, at first use the FormatDataTime function, example:

var VHora, VMinuto: integer;
Begin
  VHora := StrToInt(FormatDataTime('hh',now));  
  VMinuto := StrToInt(FormatDataTime('nn',now));
End; 

The second form as mentioned by @TiagoRodrigues, we will use the function HourOf and MinuteOf , example:

var VHora, VMinuto: integer;
Begin
  VHora := HourOf(now); 
  VMinuto := MinuteOf(now);
End; 

In the question you are only using hours and minutes, if you need seconds let me edit the answer. Any more questions please let me know.

    
28.09.2017 / 15:28
0

There is a function called DecodeDateTime , which uses Unit DateUtils and it breaks the date and time parts, so you can work with each element. Here's an example.

procedure TForm2.Button3Click(Sender: TObject);
var
  wAno, wMes, wDia : Word;
  wHora, wMinuto, wSegundos, wMilissegundo : Word;
  iHour, iMinuto: Integer;
begin
  DecodeDateTime(Now(), wAno, wMes, wDia, wHora, wMinuto, wSegundos, wMilissegundo);

  iHour := wHora;
  iMinuto := wMinuto;
end;
    
06.10.2017 / 18:40