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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare time values

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I need to verify that the time entry by a user is on the 1/2 hour or on the hour. I was going to check the last two characters for 00 or 30. Anyone know of a "better" or different way? That was the only way I could think of.

thanks!
leslie
 
You don't specify what control the user has to use to input the time.

I would be tempted to develop a component, probably based on Tedit or TStringGrid, which would only allow the user to input feasible numbers in each position.

Assuming a 24 hour clock, the first digit can only be 0, 1 or 2. The second digit can be 0 to 9 (unless the first digit is a 2 in which case it can only be 0 to 3). The third digit can only be a 0 or a 3. The fourth digit would be formatted as a 0 and cannot be changed.

Andrew
Hampshire, UK
 
I'm currently using a TEdit to capture a valid time value. I'll look into your suggestion.

thanks!
 
Quite good answer, Andrew... but I can't resist the temptation to say it remembers me that puzzle where your are asked "How old is Marduke if the combined ages of Salameh and him are 44 years, and Salameh is twice as old as Marduke was when Salameh was half as old as Marduke will be when Marduke is three times as old as Salameh was when Salameh was three times as old as Marduke."

:) :)

buho (A).

 
Leslie I assume that you are using a DateTimeField or TimeStamp somewhere in a Database.

Take the fractional part of the Field, the integer part is reserved for the days.
Remember:
1/48 = 0:30 AM,
1/24 = 1:00 AM,
15/24 = 3:00 PM
15/24 + 1/48 = 3:30 PM

To get the time out of a field, you can use something like

MyTime := frac(MyTimeField.Value);
Now you can use logical operators like <=, > etc.. to evaluate the time. Can be used for limiting a valid time span
Something like
Code:
if (MyTime >= 8/24) and (MyTime <= 17/24) then
  [b]"working hours 8:00 - 17:00"[/b]

Maybe this is not what you are looking for, but the header compare time values put me on this approach

Steven
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top