Delphi - Date Comparison Error

Asked

Viewed 189 times

2

I compared two dates. When the variable 'date' contains the date of TODAY, the code understands that it is smaller

if data < now then

  begin

  ...//se a variável DATA fosse igual a hoje (now), ele iria executar esse comando como se DATA fosse menor que NOW

  end;
  • Is he not bringing the full date (dd:mm:yyyy hh:mm:ss) ? Depending on what was recorded, he will understand that it is smaller. The good thing would be to truncate the variable in comparison...

  • I also think this is it (hh:mm:ss), how do I "truncate"?

  • Trunc(Seucampodatetime)

  • http://stackoverflow.com/questions/1760929/how-to-encode-a-datetime-in-delphi

  • It worked using Trunc, thanks .

  • I will answer her and you will accept the answer from her. It is recorded for someone who also has this doubt.

Show 1 more comment

1 answer

4


Possibly there is "confusion" in the now, which contains hour/minute/second and in the field armanezado can be any other value. To solve, you can use the command trunc:

if trunc(data) < trunc(now) then

That way you must solve your problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.