0

I have a database table 'email_log' which would be filled with information as: user, subject and opened (as datetime)

What I need is a new query from which I can see how many rows contain the column 'opened' between 08:00 and 09:00.

What I had didn't work:

SELECT count(*) as count FROM email_log WHERE opened BETWEEN '00:08:00' AND '00:09:00';

Does anyone know the trick?

Richard
  • 6,812
  • 5
  • 45
  • 60
  • possible duplicate of [mysql: get record count between two date-time](http://stackoverflow.com/questions/5786649/mysql-get-record-count-between-two-date-time) – SubSevn Sep 03 '13 at 18:11

3 Answers3

0

You might need to include the entire format for the datetime - since it's got both a date and a time.

See: mysql: get record count between two date-time

Community
  • 1
  • 1
SubSevn
  • 1,008
  • 2
  • 10
  • 27
0

try

SELECT count(*) as count FROM email_log WHERE 
opened BETWEEN STR_TO_DATE('5/15/2012', '%c/%e/%Y') 
AND STR_TO_DATE('5/15/2012', '%c/%e/%Y'); // date only

SELECT count(*) as count FROM email_log WHERE 
opened BETWEEN STR_TO_DATE('8:06:26 AM', '%r') 
AND STR_TO_DATE('8:06:26 AM', '%r'); // time only
FosterZ
  • 3,863
  • 6
  • 38
  • 62
0

Try this

SELECT COUNT(*) AS COUNT 
FROM email_log 
WHERE  DATE_FORMAT(opened,"%H:%i:%S")  > '00:08:00' AND  DATE_FORMAT(opened,"%H:%i:%S")  < '00:09:00' 
Indra Yadav
  • 600
  • 5
  • 22