Click to See Complete Forum and Search --> : Time based query


JunkMale
04-10-2010, 04:50 AM
I am trying to work out how you make a time based query, for example...

SELECT * FROM `database`.`table` WHERE `user_agent` REGEXP 'Mozilla'Will return a list of useragents that are Mozilla based / compatible. (Which was handy as I now know that my friends site is visited by 30% MSIE browsers and 70% Mozilla browsers)

I wanted to run a query on the database to find out other information, the column 'time' uses the CURRENT_TIMESTAMP as its time format and I wanted to know what is the best way of making a query for finding site visits based on time of day.

I want to gather information on:-

visitors during in work hours 9am to 5pm Mon to Fri
visitors outside those hours including Sat & Sun.

Can anyone suggest a way of doing this using a REGEXP or does a better option exist?

NogDog
04-10-2010, 10:28 PM
You could do something like:

. . .
WHERE
TIME(`time`) BETWEEN '09:00:00' AND '17:00:00' AND
DAYOFWEEK(`time`) BETWEEN 2 AND 6
. . .

JunkMale
04-11-2010, 03:30 AM
OK, thanks works a treat.