# Evaluate the hour as T or F

This has been driving me crazy for months. I hate time calculations. I have simplified my situation to just use the hour in 24 hour format since I can't find a way to do this with the datetime data.

Here's the deal, I need a function/procedure that will evaluate 3 integers and return a t/f response.  The first two values are a start and end 'hour', the third is the current 'hour'.  For example, if the start is 21, end is 6 and the current is 3, I need a false response. If the current is 7 it should return true.

In other words, if the current hour falls on 21,22,23,0,1,2,3,4,5 the response should be false, if it falls on 6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 the response should be true.

To complicate things, the start can be zero with an end of 6. Anything between 0 and 6 needs to return false, anything greater than 6 would be true.

Make sense?

Any assistance would be appreciated!!
LVL 1
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Senior DeveloperCommented:
If you are sure that the "End" integer is always going to be after the "Start" integer, then the following should work for you

// StartHour, EndHour and CurrentHourare 0 -23.
// EndHour is assumed to be after StartHour
function CheckTimeThing(StartHour, EndHour, CurrentHour: integer): boolean;
begin
if EndHour < StartHour then EndHour := EndHour + 24;  // 21, 6 becomes 21, 30
if CurrentHour < StartHour then CurrentHour := CurrentHour + 24; // 21, 30, 3 becomes 21, 30, 27
// 1, 10, 11 = 1, 10, 11 = true
// 21, 6, 3 = 21, 30, 27 = false
// 0, 6, 3 = 0, 6, 3 = false
// 0, 6, 23 = 0, 6, 23 = true
result := ( (CurrentHour < StartHour) or (CurrentHour >= EndHour) );
end;

I think this is what you mean, let me know if I'm on the wrong track
0
Commented:
Try this

function CompareHours(StartHour, EndHour, CurrentHour: integer): boolean;
begin
if StartHour <= EndHour then
result := (CurrentHour < StartHour) or (CurrentHour >= EndHour)
else
result := not ((CurrentHour < EndHour) or (CurrentHour >= StartHour));
end;

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

IT Infrastructure ManagerAuthor Commented:
MOKULE- Perfect! Thank you!
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.