Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to check time of day?

Status
Not open for further replies.

LucieLastic

Programmer
May 9, 2001
1,694
GB
hi All

The program I've written will be running constantly, 24hrs every day. I have a ttimer which stops every 30mins.

When the ttimer is triggered I want to check whether the current Time is >= 06:00 but I haven't figured it. I'm not interested in the date, just the current time in the day.

many thanks for help
lou

 
The time portion of of a TDateTime is simply the part that is to the right of the decimal point. So you can use something like this:
[blue]
Code:
procedure TForm1.Button2Click(Sender: TObject);
var
  nHours:double;
begin
  nHours :=  (Now - Int(Now)) * 24.0;
  if nHours < 6 then
    ShowMessage( 'Earlier than 6:00' )
  else
    ShowMessage( '6:00 or later' );
end;
[/color]

 
hi Zathras

I was just about to try this, don't know whether it's going to work yet

CurTime := frac(now);
if Curtime > 0.25 then //0.25 = 1/24 * 6, or 1/4
...


 
Good one. I forgot about the Frac function. Define CurTime as double and you're set to go.
 
Surely you could do this even simpler? Something like

Code:
if Time > StrToTime('06:00.00') then

or am I overlooking something blatently obvious?

Arte Et Labore [rockband]
 
Good one, Eric. That is what I hate about Delphi/Pascal there are so many reserved words that I can't keep track of them all. This should work just fine. No need to take the time to do a string conversion (pun intended):
[blue]
Code:
   if Time > .25 then
[/color]



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top