Current location: Hot Scripts Forums » Programming Languages » PHP » MySQL query between times


MySQL query between times

Reply
  #1 (permalink)  
Old 07-25-05, 03:04 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
MySQL query between times

In my table I have a column called time, and the entries in as YYYY-MM-DD

I want to query to return the records between two times as in 01:00:00 and 03:00:00

I have a dropdown list in my html form with time entries like so:

01
02
03
04
...
20
21
22
23

My SQL query just returns all rows

select * from table WHERE TIME(time) BETWEEN '01' AND '03'

Whats the correct way to do this.. ?
Reply With Quote
  #2 (permalink)  
Old 07-25-05, 06:36 AM
darkfreak's Avatar
darkfreak darkfreak is offline
Newbie Coder
 
Join Date: Jun 2004
Location: Kuopio, Finland, Europe
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by perleo
In my table I have a column called time, and the entries in as YYYY-MM-DD

I want to query to return the records between two times as in 01:00:00 and 03:00:00
If you have saved only the date (year, month, day) I guess it's impossible to get reasonable results using time (hour, minute, second). See the MySQL manual for time/date columns.
Reply With Quote
  #3 (permalink)  
Old 07-26-05, 12:55 AM
xtremenw xtremenw is offline
Newbie Coder
 
Join Date: Dec 2004
Location: Tacoma, WA
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by perleo
In my table I have a column called time, and the entries in as YYYY-MM-DD

I want to query to return the records between two times as in 01:00:00 and 03:00:00

I have a dropdown list in my html form with time entries like so:

01
02
03
04
...
20
21
22
23

My SQL query just returns all rows

select * from table WHERE TIME(time) BETWEEN '01' AND '03'

Whats the correct way to do this.. ?
try:

Code:
SELECT * FROM TABLE WHERE HOUR(time) BETWEEN 1 AND 3;
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MYSQL Distinct Query problem FunkyM PHP 20 02-28-07 08:33 AM
mysql query problem (very important for me...) pedroso PHP 5 07-26-05 01:09 AM
MySql Query - Max of Run times grouped by Runner CutAndPaste PHP 0 03-04-05 10:44 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 06:59 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.