Q:

How to compare time to a time range specified in Prolog?

Let's say i have a structure comparetime(hours,mins),
when a user keys example comparetime(10,40) ,
the structure will make comparison on a time range specified example 
timing entered
1) from 10:00 to 12:00 will print a message and 
2) from 18:00 to 20:00 will print a message .
if the time keyed is not inside the range, it will also print a message.
how can I do this ? 
it's easy to compare words but i'm really having a tough time with comparing time. 

A:

It's easy compare words? 
You should try it when internationalization is involved to appreciate how difficult could be!
Far easier is compare pair of integers, as from your problem (if I understand the question).
message_on_range(1, 10:00, 12:00, 'it\'s morning!').
message_on_range(2, 18:00, 20:00, 'it\'s evening!').

comparetime(Hours, Mins) :-
    message_on_range(_, Start, Stop, Message),
    less_equal_time(Start, Hours:Mins),
    less_equal_time(Hours:Mins, Stop),
    write(Message), nl.
comparetime(_Hours, _Mins) :-
    write('please check your clock!'), nl.

less_equal_time(H1:S1, H2:S2) :-
    H1 == H2 -> S1 =< S2 ; H1 < H2.

You should be aware of Prolog features: your problem could require a cut after the message has been printed! I.e.
...
        less_equal_time(Hours:Mins, Stop),
        write(Message), nl, !.

