How to write postgres query with time comparison ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • somaskarthic
    New Member
    • Aug 2006
    • 60

    #1

    How to write postgres query with time comparison ?

    Hi

    I'm having a table with data as follows

    ID Start_time End_time Days

    1. 06:00:00 10:00:00 { 1 }
    2. 01:00:00 05:00:00 { 2 }
    3. 22:00:00 04:00:00 {1,2}

    Here the time based on 24 hours. If it is 06 to 10 means , morning 6 to 10.
    If it is 01 to 05 , then it is early morning 1 to 5 .
    22 to 04 means midnight 10 to morning 04:00:00.

    I need to pick the id from the list , where the current time lies between start
    time and end time.

    i.e if the current time is 23:00:00 , the query should return row 3.
    If the current time is 04:00:00 , row 2 should be returned. If the current time is 09:00:00 query 1 should be returned. If the current time is 11:00:00 , no rows should be returned.

    How to write the query for this ?

    This is most urgent. Pls post your repiles

    somaskarthic
Working...