By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,638 Members | 2,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,638 IT Pros & Developers. It's quick & easy.

How to write postgres query with time comparison ?

P: 60
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
Sep 22 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.