mysql time query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

mysql time query

Post by hame22 »

Hi i am trying to select records whose time fall into a certain time period.

at the moment the query looks like this

Code: Select all

select * from activities where learn_time between 01:00:00 and 03:00:00
this brings up a query error

i'm guessing that perhaps these values may need to be formatted?

I am using php as my language

any ideas???

thanks in advance

alex
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Re: mysql time query

Post by ericburnard »

Try

Code: Select all

select * from activities where learn_time between '01:00:00' and '03:00:00'
that im not sure if it will work as i didnt know that there was a between function (there prob. is i just dont now :S) give it a go any way

Eric
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

Post by hame22 »

yeah thanks but already tried that
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

There isn't a between. Use > (more than) and < (less than).

Code: Select all

select * from activities where learn_time > '01:00:00' and learn_time < '03:00:00'
I'm not sure about the format of your time data though. If its not stored as some kind of number this won't work.
Post Reply